Question: 1) modify the operations to support priority (python) # define Python user-defined exceptions class StackUnderflowException(Exception): Stack underflow pass queue = [] def enqueue(queue, element): queue.insert(0,
1) modify the operations to support priority (python) # define Python user-defined exceptions class StackUnderflowException(Exception): "Stack underflow" pass queue = [] def enqueue(queue, element): queue.insert(0, element) def dequeue(queue): if queueLen(queue)>0: return queue.pop() else: raise StackUnderflowException() def top(queue): return queue[-1] def queueLen(queue): return len(queue) def isEmpty(queue): return len(queue)==0 try: enqueue(queue, "A") enqueue(queue, "B") enqueue(queue, "C") print(queue) #var1 = int(input("please enter a value")) print(dequeue(queue)) print(dequeue(queue)) print(dequeue(queue)) print(dequeue(queue)) print(top(queue)) except StackUnderflowException: print("You are trying to pop from an empty stack")
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
