/ Published in: C++
Ophodnja_stabla
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include<iostream> #include "prvo dijete-sljedeci brat.h" using namespace std; void Preorder(int t, tree *T){ cout <<t<<" "; if(FirstChildT(t,T)!=-1) Preorder(FirstChildT(t,T),T); if(NextSiblingT(t,T)!=-1) Preorder(NextSiblingT(t,T),T); } void Inorder(int t,tree *T){ if (FirstChildT(t,T)!=-1) Inorder(FirstChildT(t,T),T); cout <<t<<" "; if(FirstChildT(t,T)!=-1){ t=FirstChildT(t,T); while(NextSiblingT(t,T)!=-1){ t=NextSiblingT(t,T); Inorder(t,T); } } } void Postorder(int t,tree *T){ if(FirstChildT(t,T)!=-1) Postorder(FirstChildT(t,T),T); int pomkorijen=t; if(FirstChildT(pomkorijen,T)!=-1){ pomkorijen=FirstChildT(pomkorijen,T); while(NextSiblingT(pomkorijen,T)!=-1){ pomkorijen=NextSiblingT(pomkorijen,T); Postorder(pomkorijen,T); } } cout<<t<<" "; }