// A tree has a name, and a (possibly empty) list of children typedef struct _tree { char * name; struct _list * children; } tree; // A list-node has: // - some data : a pointer to a tree // - a pointer to next node typedef struct _node { struct _tree * tree; struct _node * next; } node; // A list holds: // - an int field: the current number of its nodes // - 2 pointers, to its first and last nodes respectively typedef struct _list { int nb; struct _node * first; struct _node * last; } list; // Functions for building lists and elementary checking of them node * newNode( tree * t ); list * newList( ); void addAChild( tree * t, tree * child ); void printList( list *lp ); // Functions for building trees, and simple checking of them tree * newTree( char * name ); void addANode( list * lp, node * np ); tree * newLeaf( char * name ); tree * newTreeWithGivenChildren( char * name, list *children ); void printTreeName( tree *tp ); // Functions to operate on a tree in DFS Depth First Search order: // . when arriving at some node x, the function descends // to each child y1, y2, ... in turn // . when at some son y, it does the same, etc... // // DFSPrintTree just print the node names // DFSVisitor() applies the f() function to each node // (could apply a print function as well, but may do more) void DFSPrintTree( tree * t, FILE * fp ); void DFSVisitor( tree * t, void (*f)( ), int level );