/ Published in: C++
asdf
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include <iostream> using namespace std; void preorder(tree *T){ int t = T->first; cout << t << " "; if(T->element[t].firstchild!=-1){ T->first = T->element[t].firstchild; preorder(T); } if(T->element[t].nextsibling!=-1){ T->first = T->element[t].nextsibling; preorder(T); } } void inorder(tree *T){ int t = T->first; if(T->element[t].firstchild!=-1){ T->first = T->element[t].firstchild; inorder(T); } if(T->element[t].firstchild==-1) cout << t << " "; int parent = ParentT(t,T); if(FirstChildT(parent,T)==t) cout << parent << " "; if(T->element[t].nextsibling!=-1){ T->first = T->element[t].nextsibling; inorder(T); } } void postorder(tree *T){ int t=T->first; if(T->element[t].firstchild!=-1){ T->first = T->element[t].firstchild; postorder(T); } cout << t << " "; if(T->element[t].nextsibling!=-1){ T->first = T->element[t].nextsibling; postorder(T); } }
URL: asdf