def push(self, data): self.min_stack.append(self.current_min) new_node = Node(data) new_node.next = self.head self.head = new_node if self.current_min is None or self.current_min > data: self.current_min = data
def push(self, data): if self.is_full(): return else: new_node = Node(data) new_node.next = self.head self.head = new_node self.current_size += 1
def add(self, val): newNode = Node(val) self.size += 1 if self.last: self.last.next = newNode self.last = newNode if not self.first: self.first = self.last
def push(self, data): new_node = Node(data) new_node.set_next(self.head) self.head = new_node try: min = self.min_stack.peek() if data <= min: self.min_stack.push(data) except Stack.Empty: self.min_stack.push(data)
#! /usr/bin/env python from Stack import Stack, Node node1 = Node(1) node2 = Node(2) node3 = Node(3) node4 = Node(4) node5 = Node(5) node6 = Node(6) node7 = Node(7) my_stack = Stack() my_stack.push(node1) my_stack.push(node2) my_stack.push(node3) my_stack.push(node4) my_stack.push(node5) my_stack.push(node6) my_stack.push(node7) print("Test peek") print(my_stack.peek()) print("Test pop") ret_node = my_stack.pop() print("Test node: {}".format(ret_node)) print("New top: {}".format(my_stack.peek())) print("Find Min")
def test_next(self): self.new = Stack() self.new.push("1CBA") self.new.push("2CBA") self.assertEqual(self.new.top.next, Node("1CBA"))
def SetUp(self): self.node_1 = Node("ABC") self.node_2 = Node("ABC_2")