Skip to content

Commit 8f875f5

Browse files
committed
Modified tree_sort.py
1 parent bd23e92 commit 8f875f5

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

allalgorithms/sorting/tree_sort.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
class BinaryTreeNode(object):
23
#initial values for value,left and right
34
def __init__(self, value):
@@ -26,21 +27,22 @@ def insert(tree, item):
2627
insert(tree.right, item)
2728
return tree
2829

29-
3030
# funtion for the inorder traversal of the binary tree
31-
def in_order_traversal(tree):
31+
def in_order_traversal(tree,a):
3232
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)
3535
if (tree.right != None):
36-
in_order_traversal(tree.right)
36+
in_order_traversal(tree.right,a)
3737

3838

39-
def tree_sort(x):
39+
def TreeSort(x):
4040
# root node
4141
t = insert(None, x[0]);
4242
# inserting all elements in the binary tree
4343
for i in x[1:]:
4444
insert(t,i)
4545
# 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

0 commit comments

Comments
 (0)