已知前序遍历和中序遍历的结果求后序遍历

时间:2021-06-08 12:39:00

菜鸡学习记录,贴代码:



#include <stdio.h>
#include <stdlib.h>
/** dandelion
*
* 2017-08-09
* 已知前序遍历和中序遍历的结果求后序遍历
*
*/
void changeOrderToLRD(char *pre,char *mid,int length)
{
if(0 == length)
return;
char data= *pre;
int index = 0;
for(; index<length; rootIndex++)
{
if(mid[index]==*pre)
break;
}
changeOrderToLRD(pre+1,mid,index);
changeOrderToLRD(pre+index+1,mid+index+1,length-(index+1));
printf("%c",data);
}

int main()
{
char *pre="adgxbejmc";
char *mid = "gdbxajmec";
changeOrderToLRD(pre,mid,9);
printf("\n");
return 0;
}