Skip to content
Question

Q.Write QueueUp(Client) and QueueDel(Client) methods/functions in Python to add a new Client and delete a Client from a List of Clients names, considering them to act as insert and delete operations of the Queue data structure.

(OR)
Write PushOn(Book) and Pop(Book) methods/functions in Python to add a new Book and delete a Book from a List of Book titles, considering them to act as push and pop operations of the Stack data structure.
CBSECBSE Class XII Board 2019Subjective· 4mImportance★★★★★
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Part (a): a queue is FIFO — QueueUp adds at the rear with append(), QueueDel removes from the front with pop(0).

Part (b): a stack is LIFO — PushOn adds at the top with append(), Pop removes from the top with pop().

Part (a)

A queue follows First-In-First-Out (FIFO), like people in a line: the first to join is the first served. New clients are added at the rear and removed from the front. Using a Python list, append() adds at the end and pop(0) removes the first element. Always guard the delete against an empty queue (underflow).

def QueueUp(Queue, Client):
    "Insert a new client at the rear of the queue."
    Queue.append(Client)

def QueueDel(Queue):
    "Delete and return the client at the front of the queue."
    if Queue == []:
        print("Queue Empty (Underflow)")
    else:
        return Queue.pop(0)

# demonstration
Clients = []
QueueUp(Clients, "Ravi")
QueueUp(Clients, "Sara")
QueueUp(Clients, "Tom")
print("Queue:", Clients)
print("Served:", QueueDel(Clients))
print("Queue:", Clients)
Queue: ['Ravi', 'Sara', 'Tom']
Served: Ravi
Queue: ['Sara', 'Tom'] …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.