Posted By


fstrunja on 01/12/14

Tagged


Statistics


Viewed 105 times
Favorited by 0 user(s)

ophodjenje_stabla.h


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

Implementacija algoritama ophođenja stabla (preorder, inorder, postorder)


Copy this code and paste it in your HTML
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void PreOrder (int pom) {
  5. cout << LabelT(pom, stablo) << " ";
  6. if (FirstChildT(pom, stablo)!=-1)
  7. PreOrder(FirstChildT(pom, stablo));
  8. if (NextSiblingT(pom, stablo)!=-1)
  9. PreOrder(NextSiblingT(pom, stablo));
  10. }
  11.  
  12. void InOrder (int pom) {
  13. if (FirstChildT(pom, stablo)!=-1)
  14. InOrder(FirstChildT(pom, stablo));
  15. cout << LabelT(pom, stablo) << " ";
  16. if (FirstChildT(pom, stablo)!=-1) {
  17. pom = FirstChildT(pom, stablo);
  18. while (NextSiblingT(pom, stablo)!=-1) {
  19. pom=NextSiblingT(pom, stablo);
  20. InOrder(pom);
  21. }
  22. }
  23. }
  24.  
  25. void PostOrder (int pom) {
  26. if (FirstChildT(pom, stablo)!=-1)
  27. PostOrder(FirstChildT(pom, stablo));
  28. int pomv = pom;
  29. if (FirstChildT(pomv, stablo)!=-1) {
  30. pomv=FirstChildT(pomv, stablo);
  31. while (NextSiblingT(pomv, stablo)!=-1) {
  32. pomv=NextSiblingT(pomv, stablo);
  33. PostOrder(pomv);
  34. }
  35. }
  36. cout << LabelT(pom, stablo) << " ";
  37. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.