Advertisement
zhukov000

Simple stack on static memory

Nov 9th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. MAX_SIZE = 100
  2. stack = [ 0 ] * MAX_SIZE
  3. stack_size = 0
  4.  
  5. def push(x):
  6.     global stack_size
  7.     print('ok')
  8.     stack[stack_size] = x
  9.     stack_size += 1
  10.  
  11. def back():
  12.     print( stack[stack_size-1] )
  13.  
  14. def pop():
  15.     global stack_size
  16.     back()
  17.     stack_size -= 1
  18.    
  19. def size():
  20.     print( stack_size )
  21.  
  22. def clear():
  23.     global stack_size
  24.     print('ok')
  25.     stack_size = 0
  26.  
  27. while True:
  28.     command = input()
  29.     if command == 'exit':
  30.         print('bye')
  31.         break
  32.     elif command[:4] == 'push':
  33.         push(command.split()[1])
  34.     else:
  35.         exec( command + "()" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement