Data Handling --
Tree Nodes
Each Tree Node represents a position in the tree where data can reside and where branching can take place. Tree Nodes have a parent in the tree, a depth, a data entry and a list of children. A Tree Node may have any number of child nodes.
Include file:
class TNode {
// Data
TNode* m_pnodeParent; // the node's parent node
int m_nDepth; // the node's depth in the tree
void* m_pData; // the data held at the node
List m_listChildren; // a list containing pointers to the node's
// child nodes
LNode* m_plnodeCurrentChild; // the current child node in the child list
// Functions
// see Implementation -- Tree Nodes
};
Entry parts:
The Reference to Parent Node (m_pnodeParent) points to the tree node from which this node was generated. There can only be one parent node for each node in the tree. The root node has no parent node so its Reference to Parent Node is set to NULL.
The Depth (m_nDepth) indicates at what level in the tree the tree node is at. The root node is at depth 1. The root node's child nodes are at depth 2. Each level down adds one to the depth. The Depth is useful in controlling breadth-first searches.
The Reference to Node Data (m_pData) points to the data object held in the node. The reference may point to any type of data. It is possible to hold different types of data in different nodes of the same tree, although it is usually customary that all the nodes in the same tree hold the same type of data.
The List of Child Node References (m_listChildren) holds references to all tree nodes generated from this node. This node is the parent node of all the tree nodes referenced in the List of Child Node References. If this node doesn't have any children, the List of Child Node References still exists but is empty.
The Reference to Current Child (m_plnodeCurrentChild) points to the reference of the active child node in the List of Child Node References. The active child node is the one to which actions on child nodes are directed. Upon entry to a node from its parent node, the Reference to Current Child is set to the first entry in the List of Child Node References. It is changed through various actions on the node. If the List of Child Node References is empty, the Reference to Current Child is set to NULL. Upon entry to a node from a child node, the Reference to Current Child is left at its current position. Each tree node has a Reference to Current Child.
Return ...
Andrew Tompkins
Beaverton, OR 97006
Last rev: 19 JUL 03
URL:
http://home.comcast.net/~andytom/simplan.docs/data/tree.node.html