Posted By


igotepava on 01/18/15

Tagged


Statistics


Viewed 846 times
Favorited by 0 user(s)

ophodnja_stabla.h


/ Published in: C++
Save to your folder(s)

Implementacija ophodnje stabla: Inorder, Postorder, Preorder.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.