全部完成

This commit is contained in:
2024-11-22 19:20:27 +08:00
parent 7f8acf4da1
commit 82f94bdd7c
2 changed files with 61 additions and 1 deletions
+21 -1
View File
@@ -17,5 +17,25 @@ using namespace std;
int main()
{
int n;
cout << "请输入节点个数:";
cin >> n;
string preorder, inorder;
cout << "请输入前置索引:" << endl;
cin >> preorder;
cout << "请输入后置索引:" << endl;
cin >> inorder;
std::unordered_map<char, int> inMap;
for (int i = 0; i < inorder.size(); ++i)
{
inMap[inorder[i]] = i;
}
BiTree<char>* root = BiTree<char>::buildFromPreorderInorderString(preorder, inorder, 0, n - 1, 0, n - 1, inMap);
cout << "树高为:" << BiTree<char>::getHeight(root) << endl;
cout << "该数结构为:" << endl << root->toString() << endl;
return 0;
}
}