Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def enqueue(queue, item):
- queue.append(item)
- def dequeue(queue):
- if any(queue):
- print("Item De-queued : ", queue.pop(0))
- else : print("[WARNING] Underflow!!!")
- def peek(queue):
- if any(queue):
- for i in range(len(queue)):
- if i == 0:
- print(queue[i], " <== FRONT")
- elif i == len(queue)-1 :
- print(queue[i], " <== REAR")
- else: print(queue[i], end="\n")
- else: print("[WARNING] Queue is EMPTY!!!")
- def main():
- queue = []
- print("The Queue is Empty now..\nPlease Enter 5 items into it...")
- for i in range(5):
- inp = input("Enter an Item : ")
- queue.append(inp)
- print("[SUCCESS] 5 Items Successfully added to it.")
- print("\nPlease Enter the Operation that you want to do on it...")
- while True:
- print("\n1. Enqueue\n2. Dequeue\n3. Peek\n4. Display Queue\n5. Exit")
- choice = int(input("Enter the Choice (Number only) : "))
- if choice == 1:
- item = input("Enter the Item to be pushed : ")
- enqueue(queue, item)
- print("[SUCCESS] Item Successfully En-queued into the queue.")
- elif choice == 2 : dequeue(queue)
- elif choice == 3 : peek(queue)
- elif choice == 4 :
- for i in queue : print(i)
- elif choice == 5 :
- print("Exiting...")
- break
- else : print("[ERROR] Invalid Choice")
- main()
Advertisement
Add Comment
Please, Sign In to add comment