Post-, Inorder & output of Ware
This commit is contained in:
parent
1592095d07
commit
bf104735f2
|
|
@ -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);
|
||||
|
|
@ -60,3 +60,38 @@ 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();
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue