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

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

數(shù)據(jù)結(jié)構(gòu)實驗之二叉樹七:葉子問題(二叉樹+隊列)

2019-11-11 01:15:23
字體:
供稿:網(wǎng)友

sdut原題鏈接

數(shù)據(jù)結(jié)構(gòu)實驗之二叉樹七:葉子問題 Time Limit: 1000MS Memory Limit: 65536KB

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

Input 輸入數(shù)據(jù)有多行,每一行是一個長度小于50個字符的字符串。

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

Example Input abd,,eg,,,cf,,, xnl,,i,,u,,

Example Output dfg uli

Hint 二叉樹+隊列 Author xam

以下為accepted代碼

#include <stdio.h>#include <string.h>#include <stdlib.h>typedef struct node{ char date; struct node *left; struct node *right;}BinTree;BinTree *root;BinTree *link[54];char s[54];int flag, pu, po;BinTree * creat(){ BinTree *root; if(s[flag++] == ',') root = NULL; else { root = (BinTree *)malloc(sizeof(BinTree)); root->date = s[flag-1]; root->left = creat(); root->right = creat(); } return root;}void put_leave(BinTree *root){ if(root) { pu = po = 0; link[pu++] = root; while(pu > po) { if(!link[po]->left && !link[po]->right) { printf("%c", link[po]->date); } if(link[po]->left) { link[pu++] = link[po]->left; } if(link[po]->right) { link[pu++] = link[po]->right; } po++; } }}int main(){ while(scanf("%s", s) != EOF) { flag = 0; root = creat(); put_leave(root); printf("/n"); } return 0;}/***************************************************User name:Result: AcceptedTake time: 0msTake Memory: 116KBSubmit time: 2017-02-07 16:09:24****************************************************/
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 民乐县| 驻马店市| 舒兰市| 柞水县| 扶沟县| 民权县| 民勤县| 溧阳市| 伊通| 上虞市| 洱源县| 朝阳市| 满城县| 临沭县| 兴宁市| 周至县| 彰化县| 顺义区| 库车县| 双流县| 淅川县| 威海市| 肇源县| 伊吾县| 饶平县| 德州市| 南部县| 鲁甸县| 建平县| 当阳市| 高陵县| 新竹市| 宜丰县| 南召县| 郯城县| 东港市| 聂荣县| 揭东县| 山西省| 嘉峪关市| 景洪市|