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

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

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

2019-11-11 01:51:11
字體:
供稿:網(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ā)表
主站蜘蛛池模板: 南丰县| 黄大仙区| 山阳县| 永福县| 穆棱市| 滨海县| 交口县| 屏东县| 三门峡市| 垣曲县| 禹城市| 高尔夫| 杨浦区| 新化县| 卢龙县| 双城市| 依兰县| 商南县| 莲花县| 铁力市| 曲周县| 南通市| 镇沅| 理塘县| 泌阳县| 伊吾县| 遂溪县| 达拉特旗| 银川市| 东丰县| 松桃| 姜堰市| 肇东市| 高安市| 乐安县| 昌黎县| 连州市| 安吉县| 湟中县| 常宁市| 伊宁市|