Advertisement
davide1409

Stack

Jan 10th, 2020
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. class Stack:
  2.   def __init__(self,size = 100):
  3.   #@param self: int
  4.     self.stack = []
  5.     self.size = size
  6.  
  7.   def push(self,element):
  8.   #@param element: qualsiasi tipo
  9.     if len(self.stack)<=self.size:
  10.       self.stack.append(element)
  11.     else:
  12.       print('Raggiunto limite di memoria')
  13.  
  14.   def pop(self):
  15.     self.stack = self.stack[:-1]
  16.  
  17.   def top(self):
  18.   #@return: qualsiasi tipo
  19.     if self.stack != []:
  20.       return self.stack[-1]
  21.    
  22.   def empty(self):
  23.   #@return: bool
  24.     return not self.stack
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement