Пример #1
0
        def pop(self):
            if self.is_empty():
                raise Empty("Stack is empty")
            e = self._data[self._index - 1]
            self._data[self._index - 1] = None
            self._index -= 1

            return e
Пример #2
0
    def peek(self):
        """Return but do not remove the element off the top of the stack

        :returns Element on the top of the stack

        """
        if self.is_empty():
            raise Empty("Stack is empty")
        return self._data[self._size - 1]
Пример #3
0
    def pop(self):
        """Pop the element off the top of the stack

        :returns Element on the top of the stack

        """
        if self.is_empty():
            raise Empty("Stack is empty!")
        e = self._data[self._size-1]

        self._data[self._size-1] = None
        self._min[self._size-1] = None
        self._size -= 1
        self._min.pop()

        return e
Пример #4
0
    def peek(self, s):
        """Return but do not pop the top element off the top of the stack s

        :param   s Stack number (1-3)
        :returns Reference to the element on the top of the stack s

        """
        if s not in range(1, 4):
            raise IOError(str(s) + " not in valid stack range (1-3)")

        if self.stacks[s - 1].is_empty():
            raise Empty("Stack is empty!")

        index = self._get_stack_index_reference(s) - 1

        return self.data[index]
Пример #5
0
    def pop(self):
        """Pop the first element off the first non-empty stack

        :returns Element off the top of the first non-empty stack

        """
        index = 0
        popped = False

        while index < len(self._stacks) and not popped:
            if not self._stacks[index].is_empty():
                e = self._stacks[index].pop()
                popped = True
            else:
                index += 1
        if not popped:
            raise Empty("All stacks are empty")
        return e
Пример #6
0
    def pop(self, s):
        """Pop the element off the top of the stack s

        :param   s Stack number (1-3)
        :returns The reference to the element at the top of the stack s

        """
        if s not in range(1, 4):
            raise IOError(str(s) + " not in valid stack range (1-3)")

        if self.stacks[s - 1].is_empty():
            raise Empty("Stack is empty!")

        index = self._get_stack_index_reference(s) - 1

        e = self.data[index]

        self.data[index] = None
        self.stacks[s - 1].index -= 1

        return e
Пример #7
0
 def peek(self):
     if self.is_empty():
         raise Empty("Stack is empty")
     return self._data[self._index - 1]