jtentor

DemoStack1 - Python - StackArray.py

May 11th, 2020
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 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. import numpy
  7.  
  8. class Stack(object):
  9.     def __init__(self, capacity = 10):
  10.         self.__capacity = capacity
  11.         self.__datos = numpy.empty(self.__capacity, numpy.object)
  12.         self.__count = 0
  13.  
  14.     def Push(self, x):
  15.         if self.__count >= self.__capacity :
  16.             raise ValueError("ERROR La pila está llena...")
  17.         self.__datos[self.__count] = x
  18.         self.__count += 1
  19.  
  20.     def Pop(self):
  21.         if self.Empty :
  22.             raise ValueError("ERROR La pila está vacía...")
  23.         self.__count -= 1
  24.         return self.__datos[self.__count]
  25.  
  26.     def Peek(self):
  27.         if self.Empty :
  28.             raise ValueError("ERROR La pila está vacía...")
  29.         return self.__datos[self.__count - 1]
  30.  
  31.     def Top(self):
  32.         return self.Peek()
  33.  
  34.     @property
  35.     def Empty(self):
  36.         return self.__count == 0
  37.  
  38.     @property
  39.     def Count(self):
  40.         return self.__count
  41.  
  42.  
  43. if __name__ == "__main__":
  44.     pass
Add Comment
Please, Sign In to add comment