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

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

求二叉樹的先序遍歷

2019-11-11 04:15:46
字體:
來源:轉載
供稿:網友

PRoblem Description

已知一棵二叉樹的中序遍歷和后序遍歷,求二叉樹的先序遍歷

Input

輸入數據有多組,第一行是一個整數t (t<1000),代表有t組測試數據。每組包括兩個長度小于50 的字符串,第一個字符串表示二叉樹的中序遍歷序列,第二個字符串表示二叉樹的后序遍歷序列。

Output

輸出二叉樹的先序遍歷序列

Example Input

2dbgeafcdgebfcalnixulinux

Example Output

abdegcfxnliu
 
#include<stdio.h>#include<string.h>#include<stdlib.h>typedef struct node{    char data;    struct node *lc,*rc;}bitree;bitree * create(int zlen,char hst[51],char zst[51]){    int i;    bitree *t;    if(zlen<=0)        return NULL;    t=(bitree *)malloc(sizeof(bitree));    t->data=hst[0];    for(i=0;i<zlen;i++)    {        if(zst[i]==hst[0])            break;    }    t->lc=create(i,hst-zlen+i,zst);    t->rc=create(zlen-i-1,hst-1,zst+i+1);    return t;}void preshow(bitree * tree){    bitree * t;    t=tree;    if(t)    {        printf("%c",t->data);        preshow(t->lc);        preshow(t->rc);    }}int main(){    int t,zlen,hlen;    char hst[51],zst[51];    bitree * tree;    scanf("%d",&t);    while(t--)    {        scanf("%s%s",zst,hst);        zlen=strlen(zst);        hlen=strlen(hst);        tree=create(zlen,hst+hlen-1,zst);        preshow(tree);        printf("/n");    }    return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 分宜县| 高要市| 吐鲁番市| 湘潭县| 留坝县| 定西市| 曲阳县| 阜平县| 武威市| 阳春市| 潜山县| 太保市| 濮阳市| 榆中县| 泰顺县| 大悟县| 米林县| 中阳县| 武穴市| 阜阳市| 沂南县| 阳原县| 萨迦县| 台江县| 白朗县| 于都县| 营口市| 游戏| 汶川县| 郸城县| 东丰县| 白玉县| 高阳县| 友谊县| 镇安县| 浑源县| 新绛县| 乌审旗| 宜丰县| 肇州县| 乃东县|