#include<iostream>
#include<string>
using namespace std;
void Preorder(string inorder,string postorder)
{
if(inorder.size()>0)
{
char ch=postorder[postorder.size()-1];
cout<<ch;
int k=inorder.find(ch);
Preorder(inorder.substr(0,k),postorder.substr(0,k));
Preorder(inorder.substr(k+1),postorder.substr(k,inorder.size()-k-1));
}
}
int main()
{
string inorder,postorder;
cin>>inorder;
cin>>postorder;
Preorder(inorder,postorder);
cout<<endl;
return 0;
}已知二叉树的中序和后序遍历排列,求前序遍历
二叉树前序遍历
最新推荐文章于 2025-10-20 23:38:41 发布
本文介绍了一种使用递归方法实现二叉树前序遍历的C++程序。通过输入中序和后序遍历序列,程序能够输出对应的前序遍历结果。这种方法在数据结构与算法的学习和实践中非常有用。

7667

被折叠的 条评论
为什么被折叠?



