jtentor

DemoStack1 - Python - StackList.py

May 11th, 2020
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. __author__ = 'Julio Tentor <jtentor@fi.unju.edu.ar>'
  4.  
  5.  
  6. class Stack(object):
  7.     def __init__(self, capacity = 10):
  8.         self.__datos = []
  9.  
  10.     def Push(self, elemento):
  11.         self.__datos.append(elemento)
  12.  
  13.     def Pop(self):
  14.         if self.Empty:
  15.             raise ValueError("ERROR La pila está vacía...")
  16.         return self.__datos.pop()
  17.  
  18.     def Peek(self):
  19.         if self.Empty:
  20.             raise ValueError("ERROR La pila está vacía...")
  21.         return self.__datos[len(self.__datos) - 1]
  22.  
  23.     def Top(self):
  24.         return self.Peek()
  25.  
  26.     @property
  27.     def Empty(self):
  28.         return len(self.__datos) == 0
  29.  
  30.     @property
  31.     def Count(self):
  32.         return len(self.__datos)
  33.  
  34.     def __str__(self):
  35.         return str(self.__datos)
  36.  
  37.  
  38. if __name__ == "__main__":
  39.     pass
Add Comment
Please, Sign In to add comment