예제 #1
0
 def test_to_dlinked_list(self):
     root = Node(10)
     root.left_child = Node(12)
     root.left_child.left_child = Node(25)
     root.left_child.right_child = Node(30)
     root.right_child = Node(15)
     root.right_child.left_child = Node(36)
     self.assertEqual('251230103615', root.str_in_order())
     dll = DoublyLinkedList()
     dll.head, temp = root.to_dlinked_list()
     self.assertEqual('25 12 30 10 36 15 ', str(dll))
예제 #2
0
 def test_str(self):
     root = Node('a')
     root.insert_left('b')
     root.left_child.insert_right('d')
     root.insert_right('f')
     root.insert_right('c')
     root.right_child.insert_left('e')
     self.assertEqual('bdaecf', root.str_in_order())
     self.assertEqual('abdcef', root.str_pre_order())
     self.assertEqual('dbefca', root.str_post_order())
     self.assertEqual('abcdef', root.str_bfs())
예제 #3
0
 def test_insert(self):
     root = Node(50)
     root.insert(13)
     root.insert(21)
     root.insert(27)
     root.insert(76)
     root.insert(2)
     root.insert(44)
     root.insert(51)
     root.insert(6)
     root.insert(9)
     root.insert(11)
     self.assertEqual('2691113212744505176', root.str_in_order())