diff options
-rw-r--r-- | monkey/graph.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/monkey/graph.py b/monkey/graph.py index 3e1d3a2..cbe44f7 100644 --- a/monkey/graph.py +++ b/monkey/graph.py @@ -20,6 +20,19 @@ class Node(object): target.ein.append(self) return target + # Return a list of nodes in [self]. + def preorder(self): + nodes = [self] + for n in self.eout: + nodes += n.preorder() + return nodes + + # Return a one-line string representation of [self]. + def __str__(self): + return '(' + str(self.data) + ' ' + \ + ' '.join([str(c) if c.eout else '"'+str(c.data)+'"' for c in self.eout]) + \ + ')' + def __repr__(self): return str(self.data) |