From 3631f6570e9e81e4736d39ab3b97ee50d95bb901 Mon Sep 17 00:00:00 2001 From: Omkar Kolate <53403067+omkarkolate@users.noreply.github.com> Date: Thu, 15 Aug 2019 16:10:59 +0530 Subject: [PATCH] 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". --- Data Structure/Queue Using Linked List.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Data Structure/Queue Using Linked List.cpp b/Data Structure/Queue Using Linked List.cpp index acf32ebd5..763534f83 100644 --- a/Data Structure/Queue Using Linked List.cpp +++ b/Data Structure/Queue Using Linked List.cpp @@ -35,7 +35,7 @@ void Enque(int x) void Deque() { - if (rear==front) + if (rear == NULL && front == NULL) { cout<<"\nUnderflow"; } @@ -45,6 +45,8 @@ void Deque() cout<<"\n"<val<<" deleted"; front=front->next; delete t; + if(front == NULL) + rear = NULL; } }