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

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

數據結構實驗之二叉樹二:遍歷二叉樹

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

PRoblem Description

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

Input

連續輸入多組數據,每組數據輸入一個長度小于50個字符的字符串。

Output

每組輸入數據對應輸出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;}
上一篇:TreeSet

下一篇:求二叉樹的先序遍歷

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 渭南市| 林周县| 宁明县| 左贡县| 长武县| 天长市| 阳高县| 城步| 永顺县| 拉萨市| 麦盖提县| 云梦县| 方山县| 武宣县| 广西| 怀仁县| 邢台县| 龙川县| 莲花县| 曲阜市| 吉水县| 灵石县| 将乐县| 盐山县| 电白县| 百色市| 马龙县| 金塔县| 岳普湖县| 通榆县| 石家庄市| 河曲县| 浦北县| 鄂尔多斯市| 黔西县| 方正县| 安阳市| 临武县| 尼玛县| 乌拉特后旗| 鲁甸县|