Posted By

javert on 01/19/15


Tagged

sp


Versions (?)

tree_order.h


 / Published in: C++
 

Implementacija ophođenja stabla, inoreder,postorder,preorder

  1. void PreOrderT(oTree oT, onode n)
  2. {
  3. cout << LabelT(n, oT) << ' ';
  4.  
  5. if(FirstChildT(n, oT)!=-1)
  6. PreOrderT(oT, FirstChildT(n, oT));
  7.  
  8. if(NextSiblingT(n, oT)!=-1)
  9. PreOrderT(oT, NextSiblingT(n, oT));
  10. }
  11.  
  12. void InOrderT(oTree oT, onode n)
  13. {
  14. if(FirstChildT(n, oT)!=-1)
  15. InOrderT(oT, FirstChildT(n, oT) );
  16.  
  17. cout << LabelT(n, oT) << ' ';
  18.  
  19. if(FirstChildT(n, oT)!=-1)
  20. {
  21. for(onode m=FirstChildT(n, oT); NextSiblingT(m, oT)!=-1; m=NextSiblingT(m, oT) )
  22. {
  23. InOrderT(oT, NextSiblingT(m, oT) );
  24. }
  25. }
  26. }
  27.  
  28. void PostOrderT(oTree oT, onode n)
  29. {
  30. if(FirstChildT(n, oT)!=-1)
  31. PostOrderT(oT, FirstChildT(n, oT) );
  32.  
  33. cout << LabelT(n, oT) << ' ';
  34.  
  35. if(NextSiblingT(n, oT)!=-1)
  36. PostOrderT(oT, NextSiblingT(n, oT) );
  37. }

Report this snippet  

You need to login to post a comment.