mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-06-09 07:32:51 -04:00
fix few details, binary search trees
This commit is contained in:
parent
5a7a97b25f
commit
f77b8eaaf2
15 changed files with 73 additions and 629 deletions
|
@ -1,40 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
__author__ = "Mari Wahl"
|
||||
__email__ = "marina.w4hl@gmail.com"
|
||||
|
||||
""" A class for a simple tree """
|
||||
|
||||
class SimpleTree(object):
|
||||
def __init__(self, value=None, children = None):
|
||||
self.value = value
|
||||
self.children = children
|
||||
if self.children == None:
|
||||
self.children = []
|
||||
|
||||
def __repr__(self, level=0):
|
||||
ret = "\t"*level+repr(self.value)+"\n"
|
||||
for child in self.children:
|
||||
ret += child.__repr__(level+1)
|
||||
return ret
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
'a'
|
||||
'b'
|
||||
'd'
|
||||
'e'
|
||||
'c'
|
||||
'h'
|
||||
'g'
|
||||
"""
|
||||
st = SimpleTree('a', [SimpleTree('b', [SimpleTree('d'), SimpleTree('e')] ), SimpleTree('c', [SimpleTree('h'), SimpleTree('g')]) ])
|
||||
print(st)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue