Posted By

dare10 on 01/20/14


Tagged


Versions (?)

Preorder Inorder Postorder


 / Published in: C++
 

Header datoteka u kojem se nalaze funkcije za Preorder Inorder i Postorder obilazak stabla

  1. #include <iostream>
  2. using namespace std;
  3. void Preorder(tree *T){
  4. int t=T->root;
  5. cout << t << " ";
  6. if(T->P[t].dijete!=-1){
  7. T->root = T->P[t].dijete;
  8. Preorder(T);
  9. }
  10. if(T->P[t].brat!=-1){
  11. T->root = T->P[t].brat;
  12. Preorder(T);
  13. }
  14. }
  15. void Postorder(tree *T){
  16. int t=T->root;
  17. if(T->P[t].dijete!=-1){
  18. T->root = T->P[t].dijete;
  19. Postorder(T);
  20. }
  21. cout << t << " ";
  22. if(T->P[t].brat!=-1){
  23. T->root = T->P[t].brat;
  24. Postorder(T);
  25. }
  26. }
  27. void Inorder(tree *T){
  28. int t=T->root;
  29. if(T->P[t].dijete!=-1){
  30. T->root = T->P[t].dijete;
  31. Inorder(T);
  32. }
  33. if(T->P[t].dijete==-1) cout << t << " ";
  34. int roditelj = ParentT(t,T);
  35. if(FirstChildT(roditelj,T)==t) cout << roditelj << " ";
  36. if(T->P[t].brat!=-1){
  37. T->root = T->P[t].brat;
  38. Inorder(T);
  39. }
  40. }

Report this snippet  

You need to login to post a comment.