Advertisement
rockettt

stack + front

May 15th, 2024
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. stack = []
  2. def simple_stack():
  3.     while True:
  4.         operation= input().split()
  5.         if operation[0] == "push":
  6.             stack.append(int(operation[1]))
  7.             print("ok")
  8.         elif operation[0] == "pop":
  9.             if len(stack)!=0:
  10.                 print(stack.pop(0))
  11.             else:
  12.                 print("error")
  13.         elif operation[0] == "front":
  14.             print(stack[0])
  15.         elif operation[0] == "back":
  16.             if len(stack)!=0:
  17.                 print(stack[-1])
  18.             else:
  19.                 print("error")
  20.         elif operation[0] == "size":
  21.             print(len(stack))
  22.         elif operation[0] == "clear":
  23.             stack.clear()
  24.             print("ok")
  25.         elif operation[0] == "exit":
  26.             print("bye")
  27.             break
  28.  
  29.  
  30. simple_stack()
  31.  
  32.  
Tags: #stack
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement