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

首頁 > 學院 > 開發(fā)設計 > 正文

求二叉樹的先序遍歷

2019-11-11 03:00:18
字體:
供稿:網(wǎng)友

PRoblem Description

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

Input

輸入數(shù)據(jù)有多組,第一行是一個整數(shù)t (t<1000),代表有t組測試數(shù)據(jù)。每組包括兩個長度小于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;}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 电白县| 汤阴县| 庄浪县| 马龙县| 清流县| 大埔区| 彰武县| 博湖县| 富裕县| 辰溪县| 邵东县| 井陉县| 惠安县| 武乡县| 巫山县| 景宁| 同江市| 灌阳县| 周口市| 牡丹江市| 图木舒克市| 缙云县| 阿克| 电白县| 衡水市| 临桂县| 曲阳县| 淮阳县| 自贡市| 定襄县| 胶州市| 会同县| 汕头市| 黄龙县| 博乐市| 洛南县| 九江县| 江陵县| 合川市| 屯门区| 阳高县|