Posted By

mvracan on 01/12/14


Tagged

Strukture


Versions (?)

ophodenje stabla.h


 / Published in: C++
 

zadatak4

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

Report this snippet  

You need to login to post a comment.