Advertisement
sol4r

QEQUE DATA STRUCTURE

Oct 25th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. MAX_SIZE = 5
  2. queue = MAX_SIZE*[0]
  3. front = 0
  4. rear  = 0
  5.  
  6.  
  7.  
  8. def enqueue(p):
  9.     global rear
  10.     if rear == MAX_SIZE:
  11.         print("overflow")
  12.     else:
  13.         queue[rear] = p
  14.         rear += 1
  15.  
  16.  
  17.  
  18.  
  19. def dequeue():
  20.     global front,rear
  21.     if front >= rear:
  22.         print("underflow")
  23.     else:
  24.         front += 1
  25.  
  26. while True:
  27.  
  28.     print("1 for enqueue ")
  29.     print("2 for dequeue ")
  30.     print("3 for exit")
  31.     choice = int(input())
  32.     if choice == 1:
  33.         n = int(input("enter input: "))
  34.         enqueue(n)
  35.         print(queue[front:rear])
  36.     elif choice == 2:
  37.         dequeue()
  38.         print(queue[front:rear])
  39.     elif choice == 3:
  40.         break
  41.     else:
  42.         print("wrong choice")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement