/ Published in: C++
Implementacija ophodnje stabla: Inorder, Postorder, Preorder.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
void Preorder(tr *T){ int pom = RootT(T); cout << pom << " "; if(FirstChildT(pom, T) != -1){ T->first = FirstChildT(pom, T); Preorder(T); } if(NextSiblingT(pom, T) != -1){ T->first = NextSiblingT(pom, T); Preorder(T); } } void Inorder(tr *T){ int pom = RootT(T); if(FirstChildT(pom, T) != -1){ T->first = FirstChildT(pom, T); Inorder(T); } int rod = ParentT(pom, T); if(FirstChildT(pom, T) == -1) cout << pom << " "; if(FirstChildT(rod, T) == pom) cout << rod << " "; if(NextSiblingT(pom, T) != -1){ T->first = NextSiblingT(pom, T); Inorder(T); } } void Postorder(tr *T){ int pom = RootT(T); if(FirstChildT(pom, T) != -1){ T->first = FirstChildT(pom, T); Postorder(T); } cout << pom << " "; if(NextSiblingT(pom, T) != -1){ T->first = NextSiblingT(pom, T); Postorder(T); } }