Skip to content

add tests for tree_sort #10015

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 16, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion sorts/tree_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ def inorder(root, res):


def tree_sort(arr):
"""

>>> tree_sort([5, 2, 7])
[2, 5, 7]

>>> tree_sort([5, -4, 9, 2, 7])
[-4, 2, 5, 7, 9]

>>> tree_sort([5, 6, 1, -1, 4, 37, 2, 7])
[-1, 1, 2, 4, 5, 6, 7, 37]

"""
# Build BST
if len(arr) == 0:
return arr
Expand All @@ -50,4 +62,6 @@ def tree_sort(arr):


if __name__ == "__main__":
print(tree_sort([10, 1, 3, 2, 9, 14, 13]))
import doctest

doctest.testmod()