'Visualisation of binary search tree in terminal
I am looking for a Python tool to visualize a binary search tree and also do insert and delete operations.
Something like this:
50
\
70
/ \
/ \
63 90
insert(50) insert(70) insert(90) insert(63)
and
delete(70)
50
\
63
\
\
90
Does anyone have something like?
greetz duffy6
Solution 1:[1]
I made it like this with binarytree and pybush:
# from binarytree import tree
from pybush import delete, add, Node
eingabe = int(input("First value: "))
tree_root = Node(eingabe)
while True:
eingabe2 = input("Add Value (i5) or remove value (r3) or exit(e): ")
aktion = eingabe2[:1]
wert = int(eingabe2[1:])
print(aktion, wert)
if aktion == "i":
add(tree_root, wert)
if aktion == "r":
delete(tree_root, wert)
print(tree_root)
if aktion == "e":
break
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | duffy6 |
