国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

數據結構上機測試4.1:二叉樹的遍歷與應用1

2019-11-11 02:18:34
字體:
來源:轉載
供稿:網友

PRoblem Description

輸入二叉樹的先序遍歷序列和中序遍歷序列,輸出該二叉樹的后序遍歷序列。

Input

第一行輸入二叉樹的先序遍歷序列;第二行輸入二叉樹的中序遍歷序列。

Output

輸出該二叉樹的后序遍歷序列。

Example Input

ABDCEFBDAECF

Example Output

DBEFCA
 
#include<stdio.h>#include<string.h>#include<stdlib.h>typedef struct node{    char data;    struct node *lc,*rc;}bitree;bitree * create(int hlen,char qst[51],char hst[51]){    int i;    bitree * t;    if(hlen<=0)        return NULL;    t=(bitree *)malloc(sizeof(bitree));    t->data=qst[0];    for(i=0;i<hlen;i++)    {        if(hst[i]==qst[0])            break;    }    t->lc=create(i,qst+1,hst);    t->rc=create(hlen-i-1,qst+i+1,hst+i+1);    return t;}void postshow(bitree * tree){    bitree * t;    t=tree;    if(t)    {        postshow(t->lc);        postshow(t->rc);        printf("%c",t->data);    }}int main(){    int hlen;    char qst[51],hst[51];    bitree * tree;    scanf("%s%s",qst,hst);    hlen=strlen(hst);    tree=create(hlen,qst,hst);    postshow(tree);    printf("/n");    return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新绛县| 上思县| 昔阳县| 吉木萨尔县| 梅州市| 监利县| 宁阳县| 呼玛县| 英山县| 洪洞县| 改则县| 海阳市| 寿宁县| 蕉岭县| 大安市| 密山市| 大港区| 习水县| 三亚市| 江西省| 买车| 上蔡县| 灵石县| 绥宁县| 三江| 龙州县| 延安市| 兴城市| 关岭| 新和县| 绿春县| 共和县| 乐至县| 长宁县| 黎川县| 嫩江县| 南汇区| 新乡县| 紫阳县| 花莲县| 鹿泉市|