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

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

數(shù)據(jù)結(jié)構(gòu)實(shí)驗(yàn)之二叉樹二:遍歷二叉樹

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

PRoblem Description

已知二叉樹的一個(gè)按先序遍歷輸入的字符序列,如abc,,de,g,,f,,, (其中,表示空結(jié)點(diǎn))。請(qǐng)建立二叉樹并按中序和后序的方式遍歷該二叉樹。

Input

連續(xù)輸入多組數(shù)據(jù),每組數(shù)據(jù)輸入一個(gè)長(zhǎng)度小于50個(gè)字符的字符串。

Output

每組輸入數(shù)據(jù)對(duì)應(yīng)輸出2行:第1行輸出中序遍歷序列;第2行輸出后序遍歷序列。

Example Input

abc,,de,g,,f,,,

Example Output

cbegdfacgefdba
 
#include<stdio.h>#include<string.h>#include<stdlib.h>typedef struct node{    char data ;    struct node * lc;    struct node * rc;}bitree;int i;bitree * pre_create(char str[51]){    bitree * t;    if(str[++i]!=',')    {        t=(bitree *)malloc(sizeof(bitree));        t->data=str[i];        t->lc=pre_create(str);        t->rc=pre_create(str);    }    else    {        t=NULL;    }    return t;}void inshow(bitree * tree){    bitree * t;    t=tree;    if(t!=NULL)    {        inshow(t->lc);        printf("%c",t->data);        inshow(t->rc);    }}void postshow(bitree * tree){    bitree * t;    t=tree;    if(t!=NULL)    {        postshow(t->lc);        postshow(t->rc);        printf("%c",t->data);    }}int main(){    int len;    char str[51];    bitree * tree;    while(scanf("%s",str)!=EOF)    {        i=-1;        len=strlen(str);        tree=pre_create(str);        inshow(tree);        printf("/n");        postshow(tree);        printf("/n");    }    return 0;}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 石屏县| 彩票| 文安县| 宁南县| 怀来县| 边坝县| 宁明县| 增城市| 通江县| 剑河县| 翁牛特旗| 蒲江县| 兴安县| 酒泉市| 加查县| 海宁市| 鸡西市| 永年县| 中西区| 神木县| 遂平县| 句容市| 安宁市| 奎屯市| 武平县| 晴隆县| 罗源县| 乐至县| 长治县| 定日县| 彩票| 营山县| 安多县| 巴东县| 甘洛县| 上蔡县| 保山市| 安塞县| 大洼县| 新丰县| 东平县|