rahulkchou

Queues

Feb 29th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. #Queue
  2.  
  3.  
  4.  
  5. data=""
  6. myQueue=["a","b","c","d","","",""]
  7. pointerTop=3
  8. pointerBottom=0
  9. queueMax=len(myQueue)-1
  10.  
  11.  
  12. def push():
  13.     global myQueue
  14.     global pointerTop
  15.     global pointerBottom
  16.     global data
  17.     global queueMax
  18.    
  19.     data=input("Enter your Data!: ")
  20.     if pointerTop==queueMax:
  21.         print("Sorry this queue is full!")
  22.     else:
  23.         pointerTop=pointerTop+1
  24.         myQueue[pointerTop]=data
  25.         print("Data Saved!")
  26.         print(myQueue)
  27.  
  28.  
  29. def pop():
  30.     global myQueue
  31.     global pointerTop
  32.     global pointerBottom
  33.     global data
  34.     global queueMax
  35.    
  36.     myQueue[pointerBottom]=""
  37.     print("Data Deleted")
  38.     pointerBottom=pointerBottom+1
  39.     print(myQueue)
  40.  
  41.  
  42.  
  43. while 1:
  44.     print(pointerTop,pointerBottom)
  45.     choice=input("PUSH or POP?: ")
  46.     if choice=="POP":
  47.         pop()
  48.     elif choice=="PUSH":
  49.         push()
  50.     else:
  51.         print("INVALID INPUT")
  52.  
  53.     print("===================================")
Add Comment
Please, Sign In to add comment