Tree Recovery (求后根历遍)

xiaoxiao2021-03-01  22

题目链接:https://www.luogu.org/problemnew/show/UVA536

题意:给你先序历遍,和中序历遍,让你求后序历遍.

参考博客:https://blog.csdn.net/hou_blog/article/details/50015503

#include<bits/stdc++.h> using namespace std; void back_order(char *preorder,char *inorder,int len){ if(len==0){ return ; }char node_value=*preorder; int rootIndex=0; for(;rootIndex<len;rootIndex++){ if(inorder[rootIndex]==node_value){ break; } } back_order(preorder+1,inorder,rootIndex); back_order(preorder+rootIndex+1,inorder+rootIndex+1,len-(rootIndex+1)); cout<<node_value; return ; } int main() { char a[10000],b[10000]; while(~scanf("%s%s",a,b)){ int len=strlen(a); back_order(a,b,len); cout<<endl; } return 0; }
转载请注明原文地址: https://www.6miu.com/read-3200285.html

最新回复(0)