Posted By

akljaic on 01/19/15


Tagged

tree binary


Versions (?)

ophodjenje_stabla.b


 / Published in: C++
 

URL: asdf

asdf

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

Report this snippet  

You need to login to post a comment.