File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change
1
+
1
2
class BinaryTreeNode (object ):
2
3
#initial values for value,left and right
3
4
def __init__ (self , value ):
@@ -26,21 +27,22 @@ def insert(tree, item):
26
27
insert (tree .right , item )
27
28
return tree
28
29
29
-
30
30
# funtion for the inorder traversal of the binary tree
31
- def in_order_traversal (tree ):
31
+ def in_order_traversal (tree , a ):
32
32
if (tree .left != None ):
33
- in_order_traversal (tree .left )
34
- print (tree .value )
33
+ in_order_traversal (tree .left , a )
34
+ a . append (tree .value )
35
35
if (tree .right != None ):
36
- in_order_traversal (tree .right )
36
+ in_order_traversal (tree .right , a )
37
37
38
38
39
- def tree_sort (x ):
39
+ def TreeSort (x ):
40
40
# root node
41
41
t = insert (None , x [0 ]);
42
42
# inserting all elements in the binary tree
43
43
for i in x [1 :]:
44
44
insert (t ,i )
45
45
# the results of the inorder traversal of a binary tree is a sorted
46
- in_order_traversal (t )
46
+ a = []
47
+ in_order_traversal (t ,a )
48
+ return a
You can’t perform that action at this time.
0 commit comments