Posted By


brumihali on 01/19/15

Tagged


Statistics


Viewed 371 times
Favorited by 0 user(s)

Ophodnja_stabla.h


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

Ophodnja stabla (preorder, inorder, postorder)


Copy this code and paste it in your HTML
  1. void Preorder(tr *T){
  2. int pom = RootT(T);
  3. cout << pom << " ";
  4. if(FirstChildT(pom, T) != -1){
  5. T->prvi = FirstChildT(pom, T);
  6. Preorder(T);
  7. }
  8. if(NextSiblingT(pom, T) != -1){
  9. T->prvi = NextSiblingT(pom, T);
  10. Preorder(T);
  11. }
  12. }
  13.  
  14. void Inorder(int t,tr *T){
  15. if (FirstChildT(t,T)!=-1)
  16. Inorder(FirstChildT(t,T),T);
  17. cout <<t<<" ";
  18. if(FirstChildT(t,T)!=-1){
  19. t=FirstChildT(t,T);
  20. while(NextSiblingT(t,T)!=-1){
  21. t=NextSiblingT(t,T);
  22. Inorder(t,T);
  23. }
  24. }
  25. }
  26.  
  27.  
  28. void Postorder(tr *T){
  29. int pom = RootT(T);
  30. if(FirstChildT(pom, T) != -1){
  31. T->prvi = FirstChildT(pom, T);
  32. Postorder(T);
  33. }
  34. cout << pom << " ";
  35. if(NextSiblingT(pom, T) != -1){
  36. T->prvi = NextSiblingT(pom, T);
  37. Postorder(T);
  38. }
  39. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.