diff --git a/Uebung 2/2.1/ExtendedBinaryTree.cpp b/Uebung 2/2.1/ExtendedBinaryTree.cpp index 1de58e6..db443a2 100644 --- a/Uebung 2/2.1/ExtendedBinaryTree.cpp +++ b/Uebung 2/2.1/ExtendedBinaryTree.cpp @@ -46,7 +46,7 @@ ExtendedBinaryTree::findMax(ExtendedBinaryTreeNode *node) { // (sub)tree std::string ExtendedBinaryTree::printPreorder(ExtendedBinaryTreeNode *node) { std::stringstream output; - output << node->key << std::endl; + output << *(node->key) << std::endl; if (node->left != nullptr) { output << this->printPreorder(node->left); @@ -59,4 +59,39 @@ std::string ExtendedBinaryTree::printPreorder(ExtendedBinaryTreeNode *node) { std::string ExtendedBinaryTree::printPreorder() { return this->printPreorder(this->rootNode); +} + +std::string ExtendedBinaryTree::printPostorder() { + return this->printPostorder(this->rootNode); +} + +std::string ExtendedBinaryTree::printPostorder(ExtendedBinaryTreeNode *node) { + std::stringstream output; + + if (node->left != nullptr) { + output << this->printPreorder(node->left); + } + if (node->right != nullptr) { + output << this->printPreorder(node->right); + } + output << *(node->key) << std::endl; + return output.str(); +} + +std::string ExtendedBinaryTree::printInorder() { + return this->printInorder(this->rootNode); +} + +std::string ExtendedBinaryTree::printInorder(ExtendedBinaryTreeNode *node) { + std::stringstream output; + + if (node->left != nullptr) { + output << this->printPreorder(node->left); + } + output << *(node->key) << std::endl; + + if (node->right != nullptr) { + output << this->printPreorder(node->right); + } + return output.str(); } \ No newline at end of file diff --git a/Uebung 2/2.1/ExtendedBinaryTree.h b/Uebung 2/2.1/ExtendedBinaryTree.h index e7f95d8..e97f3fa 100644 --- a/Uebung 2/2.1/ExtendedBinaryTree.h +++ b/Uebung 2/2.1/ExtendedBinaryTree.h @@ -17,6 +17,10 @@ public: ExtendedBinaryTreeNode *findMax(ExtendedBinaryTreeNode *node); std::string printPreorder(ExtendedBinaryTreeNode *node); std::string printPreorder(); + std::string printPostorder(ExtendedBinaryTreeNode *node); + std::string printPostorder(); + std::string printInorder(ExtendedBinaryTreeNode *node); + std::string printInorder(); }; // std::string printPreorder(BinaryTreeNode* node);