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

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

數據結構上機測試4.1:二叉樹的遍歷與應用1

2019-11-08 20:04:12
字體:
來源:轉載
供稿:網友

數據結構上機測試4.1:二叉樹的遍歷與應用1 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic PRoblem Description

輸入二叉樹的先序遍歷序列和中序遍歷序列,輸出該二叉樹的后序遍歷序列。 Input

第一行輸入二叉樹的先序遍歷序列; 第二行輸入二叉樹的中序遍歷序列。 Output

輸出該二叉樹的后序遍歷序列。 Example Input

ABDCEF BDAECF Example Output

DBEFCA Hint

Author

#include<stdio.h>#include<stdlib.h>#include<string.h>struct node{ int data; struct node *l, *r;};struct node *creat(int n, char *a, char *b)//二叉樹的重建與后續遍歷輸出{ int i; struct node *root; if(n == 0) return NULL; root = (struct node *) malloc (sizeof(struct node)); root -> data = a[0];//找到根節點,根節點為str1(先序序列)的第一個 for(i = 0; i < n; i++) { if(b[i] == a[0]) break; } root -> l = creat(i, a+1, b);//(左子樹的長度,左子樹在str1中開始位置的地址,左子樹在str2中開始位置的地址) root -> r = creat(n - 1 - i, a+i+1, b+i+1);//(右子樹的長度,右子樹在str1中開始位置的地址,右子樹在str2中開始位置的地址) printf("%c", root -> data);//后序遍歷輸出 return root;};int main(){ char a[11111]; char b[11111]; int n; scanf("%s%s", a, b); n = strlen(a); creat(n, a, b); printf("/n"); return 0;}

哇,說實話,二叉樹搞得我頭皮發麻,很難受,很氣。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 崇明县| 诸暨市| 根河市| 湘乡市| 萍乡市| 宜章县| 大足县| 宁都县| 和田县| 徐汇区| 吉安县| 崇阳县| 林口县| 房产| 陆川县| 阿拉善盟| 卢龙县| 潍坊市| 林芝县| 临武县| 满洲里市| 咸丰县| 永德县| 美姑县| 改则县| 苏尼特右旗| 东辽县| 佳木斯市| 永济市| 措勤县| 七台河市| 永年县| 增城市| 武宁县| 崇信县| 武川县| 广饶县| 木兰县| 瓮安县| 嘉黎县| 葫芦岛市|