改成模板类了
This commit is contained in:
+14
-9
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user