Make your own free website on Tripod.com

Contents Turbed: A Turbulent Behavior Development System News
In file gnarytree.hpp:

class GNAryTree

Generic N-Ary Tree

Public Methods

o GNAryTree(T* dt=NULL)
Creates a new tree node (uses the copy operator and creates a pointer).
o GNAryTree(GNAryTree& itree)
copy constructor
o& copyGNAryTree(GNAryTree& itree)
copy a tree into this one
oint addChild(T* dt)
adds a new child to this node for the given data (end of childs list)
oint addSubTree(GNAryTree *subtree)
adds a subtree at the end of childs list.
oint removeChild()
eliminates the current child and all of its childs
oT* getInfo()
gets this node data
oGNAryTree* getChild()
gets the current child
oT* getChildInfo()
gets the current child info
oint nextChild()
go to the next child
oint prevChild()
go to the next child
oint setCurrChildAt(int pos)
set the current child the one at the given pos
oint nChilds()
get the number of childs
oint curChild()
get the current child pos
oint setInfo(T* dt)
replaces the data for the current info
oint parcour()
tree parcour......
oint preAction()
calls data preAction
oint postAction()
calls data postAction
[more]int inPreAction()
calls data inPreAction, must be very careful with this function on nary-trees as it is going to be called n-childs times!!!
[more]int inPostAction()
calls data inPostAction, must be very careful with this function on nary-trees as it is going to be called n-childs times!!!
oint deleteTree()
delete this node and the whole subtree
o ~GNAryTree()
destroys the tree and all its subtrees
o& operator=(GNAryTree& itree)
copy operator
oint operator==(GNAryTree& itree)
comparison operator

Protected Fields

oT* data
Stored data for this node
o childs
child list


Documentation

Generic N-Ary Tree. version 1.1 last updated 1998

the data type to store in the tree node has to have a copy constructor and redefined the operator = and == to work ok (better if the type is complex or used bizzare routines)!!!!, it must have also the functions (they return TRUE/FALSE for error control:

int preAction(); int postAction(); int inPreAction(); int inPostAction(); they are used in the parcour of the tree so you must filled them depending of the method choosen (pre - in - or post order), the unused functions must be defined also and return always TRUE!!! i.e:

class T {
float info;
public:
....
T& operator=(T& data) { info=T.data; return *this; }
int operator==(T& data) { return (data.info==info); }
int preAction()         { // do init stuff for this node ; return TRUE; }
int postAction()        { // free temporary pointers after this node
.			             // processing; return TRUE; }
int inPreAction()       { // evaluate expresion; return TRUE if ok; }
int inPostAction()      { // NOP --- return TRUE; }
....
};
It requires the generic list template implementation....
oint inPreAction()
calls data inPreAction, must be very careful with this function on nary-trees as it is going to be called n-childs times!!!! called before evaluating each child.

oint inPostAction()
calls data inPostAction, must be very careful with this function on nary-trees as it is going to be called n-childs times!!!! called after evaluating each child.


This class has no child classes.
Author:
Daniel Barrero
See Also:
List
Node

Alphabetic index HTML hierarchy of classes or Java


This software was originally written by Daniel Barrero at the IRIT's Equipe Synthèse d'Images
contact: barrero@irit.fr

Generated by doc++