jtentor icon

DemoStack1 - Python - StackArray.py

jtentor | PRO | 05/11/20 08:50:59 PM UTC | 0 ⭐ | 427 👁️ | Never ⏰ | []
C++ |

1.06 KB

|

None

|

0 👍

/

0 👎

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
__author__ = 'Julio Tentor <[email protected]>'
 
 
import numpy
 
class Stack(object):
    def __init__(self, capacity = 10):
        self.__capacity = capacity
        self.__datos = numpy.empty(self.__capacity, numpy.object)
        self.__count = 0
 
    def Push(self, x):
        if self.__count >= self.__capacity :
            raise ValueError("ERROR La pila está llena...")
        self.__datos[self.__count] = x
        self.__count += 1
 
    def Pop(self):
        if self.Empty :
            raise ValueError("ERROR La pila está vacía...")
        self.__count -= 1
        return self.__datos[self.__count]
 
    def Peek(self):
        if self.Empty :
            raise ValueError("ERROR La pila está vacía...")
        return self.__datos[self.__count - 1]
 
    def Top(self):
        return self.Peek()
 
    @property
    def Empty(self):
        return self.__count == 0
 
    @property
    def Count(self):
        return self.__count
 
 
if __name__ == "__main__":
    pass

Comments