이미 알고 있는 선순과 중순 구후순

1131 단어 두 갈래 나무
두 갈래 트리의 선순 역행 시퀀스와 중순 역행 시퀀스를 입력하고 이 두 갈래 트리의 후순 역행 시퀀스를 출력합니다.
Input
첫 번째 줄에 두 갈래 나무의 순서를 입력하기; 
두 번째 줄은 두 갈래 나무의 중간 순서를 입력합니다.
Output
이 두 갈래 나무의 뒷순서를 출력합니다.
Sample Input
ABDCEF
BDAECF

Sample Output
DBEFCA

#include #include #include char str1[100],str2[100]; struct node {     char data;     struct node *l,*r; }; struct node *build(char *str1,char *str2,int s) {     int i;     struct node *root;     root=(struct node *)malloc(sizeof(struct node));     if(s<=0)         return NULL;     root->data=*str1;     for(i=0; i     {         if(str2[i]==*str1)             break;     }     root->l=build(str1+1,str2,i);     root->r=build(str1+i+1,str2+i+1,s-i-1);     return root; } void last(struct node *root) {     if(root!=NULL)     {         last(root->l);         last(root->r);         printf("%c",root->data);     } } int main() {     int st;     struct node *root;     scanf("%s",str1);     scanf("%s",str2);     st=strlen(str1);     root=build(str1,str2,st);     last(root);     return 0; }

좋은 웹페이지 즐겨찾기