Guest User

Untitled

a guest
Jan 16th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. typedef enum{notVisited, visited, noState}State;
  2.  
  3. typedef struct{
  4. State state;
  5. }VisitStatus;
  6.  
  7. typedef struct treeNode{
  8.  
  9. struct treeNode *parent;
  10. void *key;
  11. void *value;
  12. List **childList;
  13. VisitStatus *visitState;
  14. }Node;
  15.  
  16. typedef struct Tree{ //Multi walk
  17.  
  18. Node *root;
  19. int size;
  20. }Tree;
  21.  
  22. /*
  23. Algorithm: Pre-order traversal of n-ary tree:
  24. 0) Assuming node pointer is pointing to root node, which is, not NULL.
  25. 1) Visit node, if not visited
  26. 2) From that node,
  27. If first sub-tree exists, and
  28. If root node of that first sub-tree never visted,
  29. then traverse to root node of first sub-tree.
  30. 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)
  31. 3) From that node,
  32. Repeat till that node has (nthSubTree =secondSubTree, thirdSubTree, ...., nthSubTree){
  33. If nthSubTree exists, and
  34. If root node of nthSubTree not visited,{
  35. then traverse to root node of nthSubTree
  36. Go to step 1.
  37. }
  38. else{
  39. continue;
  40. }
  41. }// end repeat
  42. 4) We reach this step, because that node has,
  43. Either sub-trees exist but all sub-trees visited
  44. or
  45. No sub trees exist
  46. Reach parent node and go to step-1 for applying pre-order traversal on that node
  47. */
  48. static void preOrderTraverse(Node *n, ProcessItem action, List *list, compareTo compare){
  49. ...
  50. }
Add Comment
Please, Sign In to add comment