Posted By

AOT_code on 01/12/14


Tagged

stablo dijete brat ophodnja potomak korijen inorder preorder postorder


Versions (?)

ophodnja_stabla.h


 / Published in: C++
 

Ophodnje korištene za općenito stablo (Pre,In,Postorder).

  1. void PreOrder(tree* T){
  2. int node = T->root;
  3. cout << node << " ";
  4. if(T->array[node].firstchild != -1){
  5. T->root = T->array[node].firstchild;
  6. PreOrder(T);
  7. }
  8. if(T->array[node].nextsibling != -1){
  9. T->root = T->array[node].nextsibling;
  10. PreOrder(T);
  11. }
  12. }
  13.  
  14. void InOrder(tree* T){
  15. int node = T->root;
  16. if(T->array[node].firstchild != -1){
  17. T->root = T->array[node].firstchild;
  18. InOrder(T);
  19. }
  20. int parent = ParentT(node, T);
  21. if(T->array[node].firstchild == -1) cout << node << " ";
  22. if(FirstChildT(parent, T) == node) cout << parent << " ";
  23. if(T->array[node].nextsibling != -1){
  24. T->root = T->array[node].nextsibling;
  25. InOrder(T);
  26. }
  27. }
  28.  
  29. void PostOrder(tree* T){
  30. int node = T->root;
  31. if(T->array[node].firstchild != -1){
  32. T->root = T->array[node].firstchild;
  33. PostOrder(T);
  34. }
  35. cout << node << " ";
  36. if(T->array[node].nextsibling != -1){
  37. T->root = T->array[node].nextsibling;
  38. PostOrder(T);
  39. }
  40. }

Report this snippet  

You need to login to post a comment.