def pop(self): """Pop an item from the stack Args: self (StackArray): The Stack Returns: (int): int popped from stack """ if self.top is None: raise IndexError('') self.top, item = linked_list.pop(self.top, self.num_items - 1) self.num_items -= 1 return item
def pop(self): """method that removes the item at the top of the stack Args: No args Returns: item (any type) : the item (data) that was removed Raises: IndexError : when the stack is empty """ if self.is_empty(): raise IndexError self.top, item = llist.pop(self.top, 0) self.num_items -= 1 return item
def test_linked_list7(self): lst = None for i in range(3): lst = linked_list.insert(lst, i, i) self.assertEqual(linked_list.pop(lst, 0), (Node(1, Node(2, None)), 0)) self.assertEqual(linked_list.pop(lst, 2), (Node(0, Node(1, None)), 2))
def pop(self): """Write signature and purpose """ self.top, val = linked_list.pop(self.top, self.num_items - 1) self.num_items = self.num_items - 1 return val
def test_pop(self): self.assertEqual(pop(Node(1, Node(2, Node(3, None))), 2), (Node(1, Node(2, None)), 3)) self.assertRaises(IndexError, pop, None, 7) self.assertEqual(pop(Node(1, Node(2, Node(3, None))), 0), (Node(2, Node(3, None)), 1))