Implementation--
Tree Include Files
class TNode {
// Data
// see Data Handling -- Tree Nodes
// Functions
public:
// Constructors -- Destructors
TNode();
~TNode();
// Attributes
int GetDepth() const; // Retrieve the node's depth
void SetDepth( int nNewDepth );
// Set the node's depth
// Operations
// Parent and child retrieval
TNode* GetParent() const; // Retrieve the parent node
TNode* GetFirstChild(); // Retrieve the first child node in the child
// list
TNode* GetLastChild(); // Retrieve the last child node in the child
// list
TNode* GetNextChild(); // Retrieve the child node in the child list
// following the current one
TNode* GetPrevChild(); // Retrieve the child node in the child list
// just prior to the current one
// Data retrieval
void* GetData() const; // Retrieve the data held in the current node
int GetNumberChildren() const;// Retrieve the current number of children for
// the current node
// Node pointers settings
void SetParent( TNode* pnodeParent );
// Change the parent of the current node
void SetChildAtNodeEntry( ); // Set the current child pointer on entry to
// the node from above
// Child Addition
void AddNextChild( TNode* pnodeNewChild );
// Add a new node to the end of the current
// node's child list
void AddChildBefore( TNode* pnodeNewChild );
// Add a new node to the current node's child
// list just prior to the current child
void AddAsNextChild( TNode* pnodeParent );
// Add the current node to the end of the
// indicated node's child list
void AddAsChildBefore( TNode* pnodeParent );
// Add the current node to the indicated
// node's child list just prior to it's
// current child
// Data change
void SetData( void* pData ); // Change the data held in the current node
// Child Removal
TNode* RemoveChild(); // Remove and retrieve the current child node
// from the current node's child list if the
// removed node has no children
TNode* RemoveAsChild(); // Remove and retrieve the current node from
// it's parent's child list if the removed
// node has a parent and no children
TNode* RemoveChildIndex( int nIndex );
// Remove and retrieve the child node nIndex
// children into the current node's child
// list if the removed node has no children
TNode* RemoveTree(); // Remove and retrieve the current child node
// and it's descendent subtree from the
// current node's child list
TNode* RemoveAsTree(); // Remove and retrieve the current node and
// it's descendent subtree from it's
// parent's child list if the removed node
// has a parent
TNode* RemoveTreeIndex( int nIndex );
// Remove and retrieve the child node nIndex
// children into the current node's child
// list and it's descendent subtree
// Child finding
TNode* FindChild( const TNode* pnodeData );
// Find, and set as the current child node
// for the current node, the given node
TNode* FindChildIndex( int nIndex );
// Find, and set as the current child node
// for the current node, the child node
// nIndex nodes into the child list
};
class Tree {
// Data
// see Data Handling -- Trees
// Functions
public:
// Constructors -- Destructors
Tree();
~Tree();
// Operations
// Tree object pointer retrieval
TNode* GetRoot() const; // Retrieve the root node of the tree
TNode* GetCurrent() const; // Retrieve the current node of the tree
// Tree object pointer setting
void SetRoot( TNode* pnodeRoot );
// Change the root node of the tree
void SetCurrent( TNode* pnodeCurrent );
// Change the current node of the tree
// Node data retrieval with current node pointer setting
void* GetRootNode(); // Retrieve the data held in the root node
void* GetCurrentNode() const; // Retrieve the data held in the current
// node
void* GetParentNode(); // Retrieve the data held in the parent of
// the current node and set the parent
// node as the current node
void* GetFirstChildNode(); // Retrieve the data held in the first child
// node in the current node's child list
// and set that node as the current node
void* GetNextChildNode(); // Retrieve the data held in the child node
// following the current child in the
// current node's child list and set that
// node as the current node
void* GetChildNodeIndex( int nIndex );
// Retrieve the data held in the child node
// nIndex nodes into the current node's
// child list and set that node as the
// current node
// Node and subtree addition
BOOL AddRootNode( void* pData );
// Add a root node to an empty tree
BOOL AddChildNode( void* pData );
// Add a new child node to the end of the
// current node's child list
BOOL AddChildNodeBefore( void* pData );
// Add a new child node to the current
// node's child list just prior to the
// current node's current child node
BOOL AddChildNodeIndex( void* pData, int nIndex );
// Add a new child node nIndex nodes into
// the current node's child list
BOOL AddTree( const Tree& treeSubTree );
// Add a subtree to this tree placing the
// root node of the subtree at the end of
// this tree's current node's child list
BOOL AddTreeBefore( const Tree& treeSubTree );
// Add a subtree to this tree placing the
// root node of the subtree just prior to
// the current child node of this tree's
// current node
BOOL AddTreeIndex( const Tree& treeSubTree, int nIndex );
// Add a subtree to this tree placing the
// root node of the subtree as the child
// node nIndex children into this tree's
// current node's child list
BOOL AddTreeAsChildNode( Tree& treeParent );
// Add this tree as a subtree into another
// tree placing this tree's root node at
// the end of the other tree's current
// node's child list
BOOL AddTreeAsChildNodeBefore( Tree& treeParent );
// Add this tree as a subtree into another
// tree placing this tree's root node just
// prior to the current child node of the
// other tree's current root node
BOOL AddTreeAsChildNodeIndex( Tree& treeParent, int nIndex );
// Add this tree as a subtree into another
// tree placing this tree's root node as
// the child node nIndex children into the
// other tree's current node's child list
// Data change
BOOL ChangeCurrentNodeData( void* pData );
// Change the data held at the current node
void RemoveAll(); // Remove all nodes from the tree
// Node and subtree removal and destruction
void RemoveChildren(); // Remove all descendent nodes of the
// current node from the tree
void* EraseChildNode(); // Retrieve the data held at the current
// node's current child node and remove
// the child node if it has no children
void* EraseAsChildNode(); // Retrieve the data held at the current
// node and remove it if it has no
// children
void* EraseChildNodeIndex( int nIndex );
// Retrieve the data held at the node nIndex
// children into the current node's child
// list and remove the node if it has no
// children
void RemoveTree( Tree& treeRemove );
// Remove the current node's current child
// (and it's subtree) from the tree and
// set it as root of a new tree
void RemoveAsTree( Tree& treeRemove );
// Remove the current node (and it's
// subtree) from the tree and set it as
// root of a new tree
void RemoveTreeIndex( Tree& treeRemove, int nIndex );
// Remove the node nIndex children into the
// current node's child list (and it's
// subtree) from the tree and set it as
// root of a new tree
void EraseSubTree(); // Remove and destroy the current node's
// current child (and it's subtree).
void EraseAsSubTree(); // Remove and destroy the current node (and
// it's subtree)
void EraseSubTreeIndex( int nIndex );
// Remove and destroy the child nIndex
// children into the current node's child
// list (and it's subtree)
// Ordered node retrieval
void* GetNextNodePrefix( BOOL& bDone );
// Retrieve the data held at the next node
// in prefix order and set that node as
// the current node
void* GetNextNodePostfix( BOOL& bDone );
// Retrieve the data held at the next node
// in postfix order and set that node as
// the current node
// Node depth adjustment
void ChangeNodeDepths( TNode* pnodeStartNode );
// Adjust the depths of nodes in a tree
};
Return ...
Andrew Tompkins
Beaverton, OR 97006
Last rev: 18 JUL 03
URL:
http://home.comcast.net/~andytom/simplan.docs/control/include/tree.h.html