something is wrong with my dequeue function. When i try to output the value that's about to get deleted i get garbage on the console window. the enqueue function works fine.
class Queue
{
private:
int value;
Queue *next;
public:
void dequeue();
void enqueue (int num);
};
Queue *head=NULL;
void Queue::dequeue()
{
Queue *temp1,*temp2;
if(head==NULL)
cout<<"Can’t dequeue, the Queue is empty" << endl;
else
{
temp1=head;
temp2=temp1;
while(temp1->next!=NULL)
{
temp2=temp1;
temp1=temp1->next;
}
if(temp1==temp2)
{
cout<<temp1->value<<", ";
head=NULL;
}
else
{
cout<<temp1->value<<", ";
temp2->next=NULL;
delete temp1;
}
}
}
void Queue::enqueue (int num)
{
Queue *temp;
temp = new Queue;
temp->value;
cout << "print" << num << endl;
if (head == NULL)
{
temp->next=NULL;
head = temp;
}
else
{
temp->next=head;
head=temp;
}
}