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

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

數據結構實驗之二叉樹七:葉子問題

2019-11-10 19:13:31
字體:
來源:轉載
供稿:網友

PRoblem Description

已知一個按先序輸入的字符序列,如abd,,eg,,,cf,,,(其中,表示空結點)。請建立該二叉樹并按從上到下從左到右的順序輸出該二叉樹的所有葉子結點。

Input

輸入數據有多行,每一行是一個長度小于50個字符的字符串。

Output

按從上到下從左到右的順序輸出二叉樹的葉子結點。

Example Input

abd,,eg,,,cf,,,xnl,,i,,u,,

Example Output

dfguli
 
#include<stdio.h>#include<string.h>#include<stdlib.h>#define maxsize 50typedef struct node{    char data;    struct node *lc,*rc;}bitree;bitree *queue[51];int front=0,rear=0;int i=-1;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 enter_queue(bitree * t){    if((rear+1)%maxsize!=front)    {        rear=(rear+1)%maxsize;        queue[rear]=t;    }}bitree * delete_queue(bitree * t){    if(rear!=front)    {        front=(front+1)%maxsize;        return queue[front];    }}void level_order(bitree * t){    bitree * p;    if(t)    {        enter_queue(t);    }    while(front!=rear)    {        p=delete_queue(t);        if(p->lc)        {            enter_queue(p->lc);        }        if(p->rc)        {            enter_queue(p->rc);        }        if(p->lc==NULL&&p->rc==NULL)        {            printf("%c",p->data);        }    }}int main(){    char str[51];    bitree *tree;    while(scanf("%s",str)!=EOF)    {        i=-1;        tree=pre_create(str);        level_order(tree);        printf("/n");    }    return 0;}

 


上一篇:STM32L152 STOP模式

下一篇:MySQL索引

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 玛纳斯县| 万山特区| 丽水市| 巴林左旗| 富顺县| 伽师县| 二手房| 调兵山市| 贵南县| 周宁县| 柳州市| 丘北县| 禄劝| 通榆县| 南投县| 中西区| 黑水县| 方城县| 辽阳县| 乐都县| 珠海市| 林周县| 岫岩| 济源市| 来宾市| 隆林| 远安县| 荥阳市| 儋州市| 罗山县| 曲水县| 新乡市| 宜兴市| 三明市| 邳州市| 安阳市| 上犹县| 乐业县| 黑水县| 丰城市| 兴安盟|