This commit is contained in:
e2hang
2025-08-09 19:23:37 +08:00
parent ac48a86396
commit 17105e9e9e
13 changed files with 194 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
#include <iostream>
#include <string>
#include <vector>
#include "linkedBinaryTree.h"
using namespace std;
vector<string> m;
void func(binaryTreeNode<string>* node) {
cout << node->element;
}
int main() {
/*
* x
* + -
* a b c d
*/
//构建要从下往上构建,注意如果是 new了一个[]必须delete []而不能直接delete t[i]
auto t0 = new binaryTreeNode<string>("a");
auto t1 = new binaryTreeNode<string>("b");
auto t2 = new binaryTreeNode<string>("c");
auto t3 = new binaryTreeNode<string>("d");
auto t4 = new binaryTreeNode<string>("+", t0, t1);
auto t5 = new binaryTreeNode<string>("-", t2, t3);
auto t6 = new binaryTreeNode<string>("x", t4, t5);
linkedBinaryTree<string> tree(t6);
cout << endl;
tree.inOrder(func);
cout << endl;
tree.preOrder(func);
cout << endl;
tree.postOrder(func);
cout << endl;
tree.levelOrder(func);
cout << endl;
return 0;
}
/*
Output:
((a+b)x(c-d))
(x(+ab)(-cd))
((ab+)(cd-)x)
x+-abcd
disposing a
disposing b
disposing +
disposing c
disposing d
disposing -
disposing x
*/