#reverse a queue using a stack #determine if data structure is empty def isEmpty(struct): if len(struct) == 0: empty = True else: empty = False #endif return empty #endsub #dequeue an item def dequeue(q): if isEmpty(q): print ("Queue is empty") else: qItem = q.pop(0) print("queue is",q) #endif return qItem #endsub #push item onto stack def push (s,item): s.append(item) print("stack ",s) #endsub #main q1 = ['a', 'b', 'c', 'd', 'e'] s = [] q2 = [] print(q1) #take all the items out of the queue and put them on the stack while not isEmpty(q1): qItem = dequeue(q1) s.append(qItem) #endwhile print("stack is",s) #now put all items from the stack into the second queue while not isEmpty(s): stackItem = s.pop() print(s) q2.append(stackItem) #endwhile print("reversed queue ", q2)