国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 永宁县| 乐至县| 奈曼旗| 临江市| 兰州市| 科尔| 石泉县| 武冈市| 林州市| 射阳县| 万安县| 芦山县| 衡山县| 政和县| 昌平区| 德阳市| 抚宁县| 德格县| 阳西县| 涿鹿县| 河池市| 民勤县| 吕梁市| 福鼎市| 无棣县| 岳阳县| 鄄城县| 武义县| 瑞安市| 黄大仙区| 吉林市| 耿马| 德钦县| 射洪县| 宁海县| 孝昌县| 天门市| 邵东县| 南汇区| 舟山市| 米林县|