改成模板类了

This commit is contained in:
2024-11-22 17:55:29 +08:00
parent 7037512838
commit aff7b6b84e
5 changed files with 93 additions and 152 deletions
+14 -9
View File
@@ -11,8 +11,9 @@
* CBEGDFA
*/
#include <iostream>
#include <sstream>
#include "BiTree.h"
using namespace std;
int main()
@@ -22,23 +23,27 @@ int main()
cin >> input;
size_t index = 0;
BiTree* root = BiTree::build_from_preorder_string(input, index);
BiTree<char>* root = BiTree<char>::buildFromPreorderString(input, index); // 构建字符型二叉树
ostringstream oss;
if (root)
{
root->inOrder(oss);
cout << "中序遍历结果:" << oss.str() << endl;;
root->destory();
// 中序遍历
root->inorderTraversal(oss);
cout << "中序遍历结果:" << oss.str() << endl;
// 打印树结构
cout << "该树结构为:" << endl;
cout << root->toString();
// 销毁树,释放内存
root->destroy();
delete root;
}
else
{
cout << "输入的二叉树为空" << endl;
cout << "输入的二叉树为空" << endl;
}
//cout << "该树结构为:" << endl;
//cout << root->toString() << endl;
return 0;
}