I have following function to print trees in in order that works properly:
void PrintInOrder(TTreeNode const * const pRoot) {
if (pRoot != 0) {
PrintInOrder(pRoot->pLeft);
if(pRoot->pLeft) std::cout << ",";
std::cout << pRoot->Data;
if(pRoot->pRight) std::cout << ",";
PrintInOrder(pRoot->pRight);
}
}
This is my preorder printing function:
void PrintPreOrder(TTreeNode const * const pRoot) {
if (pRoot != 0) {
std::cout << pRoot->Data << std::endl;
PrintPreOrder(pRoot->pLeft);
PrintPreOrder(pRoot->pRight);
}
}
As i'm too stupid to figure it out how to print it separated the way like the inorder function i hope you guys can help me out!
thanks!
Update:
Preorder function works now, so is this the right postorder function?
void PrintPostOrder(TTreeNode const * const pRoot) {
if (pRoot != 0) {
PrintPostOrder(pRoot->pLeft);
if(pRoot->pLeft) std::cout << ",";
PrintPostOrder(pRoot->pRight);
if(pRoot->pRight) std::cout << ",";
std::cout << pRoot->Data;
}
}