-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDAG.py
More file actions
23 lines (18 loc) · 651 Bytes
/
DAG.py
File metadata and controls
23 lines (18 loc) · 651 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from DAGNode import DAGNode
import pprint as pp
class DAG:
"""
Class representing a DAG search structure with a reference
to the root node
"""
def __init__(self, root):
assert isinstance(root, DAGNode)
self.root = root
def in_order(self, node):
if node:
yield from self.in_order(node.left_child)
yield node
yield from self.in_order(node.right_child)
def __repr__(self):
return '<DAG>\n\t' + pp.pformat(list(self.in_order(self.root)), indent=4) + '\n</DAG>'
# return '<DAG: \n%s>' % '\n\n'.join(str(n) for n in list(self.in_order(self.root)))