Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef enum{notVisited, visited, noState}State;
- typedef struct{
- State state;
- }VisitStatus;
- typedef struct treeNode{
- struct treeNode *parent;
- void *key;
- void *value;
- List **childList;
- VisitStatus *visitState;
- }Node;
- typedef struct Tree{ //Multi walk
- Node *root;
- int size;
- }Tree;
- /*
- Algorithm: Pre-order traversal of n-ary tree:
- 0) Assuming node pointer is pointing to root node, which is, not NULL.
- 1) Visit node, if not visited
- 2) From that node,
- If first sub-tree exists, and
- If root node of that first sub-tree never visted,
- then traverse to root node of first sub-tree.
- Go to step 1 and continue until a node (that has visted root of first sub-tree) or (that has no first sub-tree exists)
- 3) From that node,
- Repeat till that node has (nthSubTree =secondSubTree, thirdSubTree, ...., nthSubTree){
- If nthSubTree exists, and
- If root node of nthSubTree not visited,{
- then traverse to root node of nthSubTree
- Go to step 1.
- }
- else{
- continue;
- }
- }// end repeat
- 4) We reach this step, because that node has,
- Either sub-trees exist but all sub-trees visited
- or
- No sub trees exist
- Reach parent node and go to step-1 for applying pre-order traversal on that node
- */
- static void preOrderTraverse(Node *n, ProcessItem action, List *list, compareTo compare){
- ...
- }
Add Comment
Please, Sign In to add comment