blob: 6401469d10b64668380b7876c19c8f51311d37a9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
from binarytree import *
class Diagram(object):
"""represents a syntactic structure (wrapper for binary tree)
"""
def __init__(self, height=3, size=None):
self.tree = tree(height=height)
if isinstance(size, int):
if size>height and size<((2^(height+1))-1):
while self.tree.size != size:
self.tree = tree(height=height)
else:
# raise NodeNotFoundError('no node to delete at index {}')
print('syntax diagram impossible for height'+height+'and size'+size)
def print(self):
self.tree.pprint(index=True, delimiter='\'')
'''
# example
dee = Diagram()
dee.print()
'''
|