class Node

A Node is a vertex in a Tree. All but the root have a branch.

A Node has pointers to its parent, leftChild, and sibling, any of which may be None.


Returns the number of children that the node has.


Asks whether self is an an ancestor of otherNode.


Iterates over all the nodes below self (including self)

Starts by returning self. And then iterates over all nodes below self.

It does so by a combination of Node.iterPreOrder() and Node.iterDown() (ie recursively). Now sometimes we want to know if the nodes that are returned come from iterDown() (strictly) or not (ie from iterPreOrder()). If that bit of info is needed, then you can turn on the arg showDown. (The following is probably bad Python practice!) When that is done, whenever iterDown() is called the first node that is returned will have the attribute down set to True. But after it is returned, that down attribute is zapped (to try to keep the bloat down ...). So you need to test if hasattr(yourNode, 'down'): before you actually use it.


Find and return the sibling on the left.

A node has a pointer to its sibling, but that is the sibling on the right. It is a bit awkward to find the sibling on the left, as you need to go via the parent and the leftChild of the parent.

If there is no parent, return None. If there is no leftSibling, return None.


Find and return the rightmostChild of self.

If self has no children, return None.


Set the pointers parent, leftChild, and sibling to None