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

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

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

2019-11-11 02:49:28
字體:
供稿:網(wǎng)友

PRoblem Description

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

Input

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

Output

每組輸入數(shù)據(jù)對應(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ā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 工布江达县| 赫章县| 兴和县| 南陵县| 涞水县| 上饶县| 黑龙江省| 沙坪坝区| 江源县| 沙雅县| 西华县| 永年县| 上高县| 旬阳县| 察雅县| 漳平市| 南充市| 塘沽区| 琼结县| 彭水| 黄陵县| 延庆县| 崇州市| 宁海县| 博客| 搜索| 巴楚县| 枞阳县| 潞西市| 安平县| 广宗县| 庐江县| 巴林左旗| 镇康县| 白城市| 侯马市| 文登市| 阜阳市| 宜兰县| 曲水县| 龙游县|