全部完成
This commit is contained in:
+21
-1
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user