Ejemplo n.º 1
0
class Stack:
    def __init__(self):
        self.items = UnorderedList()

    def __str__(self):
        return self.items.__str__()

    def push(self, item):
        self.items.append(item)

    def pop(self):
        return self.items.pop()

    def peek(self):
        current = self.items.head
        for i in range(self.items.length() - 1):
            current = current.getNext()
        return current.getData()

    def size(self):
        return self.items.length()
Ejemplo n.º 2
0
class Deque:
    def __init__(self):
        self.items = UnorderedList()

    def __str__(self):
        return self.items.__str__()

    def addFront(self, item):
        self.items.add(item)

    def addRear(self, item):
        self.items.append(item)

    def removeFront(self):
        return self.items.popPos(0)

    def removeRear(self):
        return self.items.pop()

    def isEmpty(self):
        return self.items.isEmpty()

    def size(self):
        return self.items.length()