Posted By

igotepava on 01/18/15


Tagged

data tree structures inorder preorder postorder


Versions (?)

ophodnja_stabla.h


 / Published in: C++
 

Implementacija ophodnje stabla: Inorder, Postorder, Preorder.

  1. void Preorder(tr *T){
  2. int pom = RootT(T);
  3. cout << pom << " ";
  4. if(FirstChildT(pom, T) != -1){
  5. T->first = FirstChildT(pom, T);
  6. Preorder(T);
  7. }
  8. if(NextSiblingT(pom, T) != -1){
  9. T->first = NextSiblingT(pom, T);
  10. Preorder(T);
  11. }
  12. }
  13.  
  14. void Inorder(tr *T){
  15. int pom = RootT(T);
  16. if(FirstChildT(pom, T) != -1){
  17. T->first = FirstChildT(pom, T);
  18. Inorder(T);
  19. }
  20. int rod = ParentT(pom, T);
  21. if(FirstChildT(pom, T) == -1) cout << pom << " ";
  22. if(FirstChildT(rod, T) == pom) cout << rod << " ";
  23. if(NextSiblingT(pom, T) != -1){
  24. T->first = NextSiblingT(pom, T);
  25. Inorder(T);
  26. }
  27. }
  28.  
  29. void Postorder(tr *T){
  30. int pom = RootT(T);
  31. if(FirstChildT(pom, T) != -1){
  32. T->first = FirstChildT(pom, T);
  33. Postorder(T);
  34. }
  35. cout << pom << " ";
  36. if(NextSiblingT(pom, T) != -1){
  37. T->first = NextSiblingT(pom, T);
  38. Postorder(T);
  39. }
  40. }

Report this snippet  

You need to login to post a comment.