#include #include #include #include "linkedBinaryTree.h" using namespace std; vector m; void func(binaryTreeNode* node) { cout << node->element; } int main() { /* * x * + - * a b c d */ //构建要从下往上构建,注意如果是 new了一个[],必须delete []而不能直接delete t[i] auto t0 = new binaryTreeNode("a"); auto t1 = new binaryTreeNode("b"); auto t2 = new binaryTreeNode("c"); auto t3 = new binaryTreeNode("d"); auto t4 = new binaryTreeNode("+", t0, t1); auto t5 = new binaryTreeNode("-", t2, t3); auto t6 = new binaryTreeNode("x", t4, t5); linkedBinaryTree 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 */