示例#1
0
    def testPush(self):
        stack = StackLinkedList()

        stack.push(0)
        stack.push(1)

        self.assertEqual(2, stack.num_elements)
示例#2
0
    def testPopOnNonEmptyStack(self):
        stack = StackLinkedList()

        stack.push(0)
        stack.push(1)
        stack.push(2)

        self.assertEqual(2, stack.pop())
        self.assertEqual(2, stack.size())
示例#3
0
    def testIsEmptyOnNonEmptyStack(self):
        stack = StackLinkedList()

        stack.push(0)
        stack.push(1)
        stack.push(2)

        self.assertFalse(stack.is_empty())
示例#4
0
    def testSizeMethod(self):
        stack = StackLinkedList()

        stack.push(0)
        stack.push(1)
        stack.push(2)

        self.assertEqual(3, stack.size())
示例#5
0
def pre_order(root_node):
    s = StackLinkedList()
    t = root_node

    while t is not None or s.is_empty() != True:
        if t is not None:
            print(t.data)
            s.push(t)
            t = t.left_child
        else:
            t = s.pop()
            t = t.right_child
示例#6
0
    def testPopOnEmptyStack(self):
        stack = StackLinkedList()

        self.assertEqual(None, stack.pop())
示例#7
0
    def testIsEmptyOnEmptyStack(self):
        stack = StackLinkedList()

        self.assertTrue(stack.is_empty())