Posted By

cindri_marko on 01/19/15


Tagged

ophodenje


Versions (?)

Ophodenje.h


 / Published in: C++
 

Ophodenje.h

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

Report this snippet  

You need to login to post a comment.