mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
Update in Deque() fuction
Because of earlier logic not going to deque the last element of the queue because at the last front == rear as per your logic which directly results in "Underflow".
This commit is contained in:
parent
71b03523dd
commit
3631f6570e
@ -35,7 +35,7 @@ void Enque(int x)
|
|||||||
|
|
||||||
void Deque()
|
void Deque()
|
||||||
{
|
{
|
||||||
if (rear==front)
|
if (rear == NULL && front == NULL)
|
||||||
{
|
{
|
||||||
cout<<"\nUnderflow";
|
cout<<"\nUnderflow";
|
||||||
}
|
}
|
||||||
@ -45,6 +45,8 @@ void Deque()
|
|||||||
cout<<"\n"<<t->val<<" deleted";
|
cout<<"\n"<<t->val<<" deleted";
|
||||||
front=front->next;
|
front=front->next;
|
||||||
delete t;
|
delete t;
|
||||||
|
if(front == NULL)
|
||||||
|
rear = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user