Revision Summary: Queue (NCERT Class 12)
append() adds at rear and pop(0) removes from front.python
myQueue = list() # create empty queue
python
def enqueue(myQueue, element):
myQueue.append(element) # insert at rear
python
def isEmpty(myQueue):
if len(myQueue) == 0:
return True
else:
return False
python
def dequeue(myQueue):
if not isEmpty(myQueue):
return myQueue.pop(0) # remove from front
else:
print("Queue is empty")
python
def size(myQueue):
return len(myQueue)
python
def peek(myQueue):
if isEmpty(myQueue):
print("Queue is empty")
return None
else:
return myQueue[0]
Deque functions (NCERT forms)
python
def insertFront(myDeque, element):
myDeque.insert(0, element)
python
def insertRear(myDeque, element):
myDeque.append(element)
python
def deletionRear(myDeque):
if not isEmpty(myDeque):
return myDeque.pop()
else:
print("Deque empty")
python
def deletionFront(myDeque):
if not isEmpty(myDeque):
return myDeque.pop(0)
else:
print("Deque empty")
python
def getFront(myDeque):
if not isEmpty(myDeque):
return myDeque[0]
else:
print("Queue empty")
python
def getRear(myDeque):
if not isEmpty(myDeque):
return myDeque[len(myDeque)-1]
else:
print("Deque empty")
Palindrome checking using Deque (Algorithm 4.1)
Step 1: Traverse the string character by character from left to right.
Step 2: Insert each character at the rear using INSERTREAR.
Step 3: Repeat until all characters are inserted.
Step 4: Remove one character from front (DELETIONFRONT) and one from rear (DELETIONREAR).
Step 5: Compare the two removed characters.
Step 6: If they match, repeat Steps 4–5 until deque is empty or has one character left → string is palindrome; else stop (not palindrome).
Basic queue operation sequence (from Fig. 4.3)
ENQUEUE → ENQUEUE → ENQUEUE → DEQUEUE → ENQUEUE → DEQUEUE → DEQUEUE (Front moves right, Rear moves right on insertion).
isEmpty() before DEQUEUE/DELETION → underflow not handled, marks lost.pop() instead of pop(0) for front deletion (removes from wrong end).None returned by peek/dequeue on empty structure without handling the message.A study aid reviewed by GFIS faculty — always verify with your textbook and teacher.