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

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

求二叉樹的先序遍歷

2019-11-11 02:49:05
字體:
來源:轉載
供稿:網友

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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 翼城县| 密山市| 商水县| 兴安县| 荆州市| 丁青县| 绵阳市| 木里| 富平县| 枝江市| 襄垣县| 临沭县| 禄丰县| 察隅县| 麦盖提县| 图木舒克市| 新民市| 韶关市| 镇雄县| 伊通| 铜山县| 海盐县| 陆河县| 蒲江县| 永城市| 怀安县| 荃湾区| 东平县| 彭阳县| 壤塘县| 孝义市| 阳西县| 金湖县| 新民市| 永丰县| 商城县| 葵青区| 邵阳县| 普兰店市| 清苑县| 长治县|