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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy