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

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

1020. Tree Traversals (25) PAT甲級

2019-11-14 10:14:42
字體:
來源:轉載
供稿:網友

傳送門

#include<stdio.h>#include<queue>using namespace std;#define MAX_N 37int inorder[MAX_N],postorder[MAX_N];typedef struct Node{ int data; Node *lchild,*rchild;}node,*Btree;void create(Btree &bt,int posL,int posR,int inL,int inR){ if(posL>posR){ bt=NULL; return; } bt=new node; bt->data=postorder[posR]; int leftnum; int i; for(i=inL;i<=inR;i++){ if(inorder[i]==postorder[posR]){ leftnum=i-inL; break; } } create(bt->lchild,posL,posL+leftnum-1,inL,i-1); create(bt->rchild,posL+leftnum,posR-1,i+1,inR);}void PReorder(Btree root){ if(root==NULL) return ; else{ preorder(root->lchild); printf("%d ",root->data); preorder(root->rchild); }}void level(Btree root,int n){ queue<Btree> q; int count=0; q.push(root); while(!q.empty()){ Btree bt=q.front(); q.pop(); printf("%d",bt->data); count++; if(count<n) printf(" "); if((bt->lchild)!=NULL) {q.push(bt->lchild);} if((bt->rchild)!=NULL) {q.push(bt->rchild);} }}int main(){ int n; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",&postorder[i]); } for(int i=0;i<n;i++){ scanf("%d",&inorder[i]); } Btree root=NULL; create(root,0,n-1,0,n-1); level(root,n); //preorder(root);}
上一篇:寫在17年開始

下一篇:ctags的使用

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 翼城县| 古田县| 都兰县| 麻栗坡县| 霍州市| 阳春市| 新河县| 平罗县| 浪卡子县| 博野县| 江城| 贵定县| 札达县| 金堂县| 平山县| 克拉玛依市| 德钦县| 怀宁县| 曲松县| 呼伦贝尔市| 图木舒克市| 宜黄县| 恭城| 怀柔区| 太仆寺旗| 南城县| 邛崃市| 略阳县| 青冈县| 孟津县| 平湖市| 丹东市| 克拉玛依市| 沙田区| 南漳县| 达州市| 云南省| 祁门县| 新宾| 年辖:市辖区| 新安县|