国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 莆田市| 清原| 禹州市| 广丰县| 岑巩县| 冷水江市| 兰考县| 长乐市| 泽库县| 清苑县| 星子县| 普兰县| 崇阳县| 南召县| 台安县| 白山市| 武强县| 淳化县| 新丰县| 德庆县| 民勤县| 施秉县| 额敏县| 新密市| 息烽县| 赤城县| 海淀区| 芷江| 临泽县| 雷州市| 龙门县| 方城县| 灌阳县| 浏阳市| 吴堡县| 外汇| 涞水县| 稻城县| 大洼县| 分宜县| 通化县|