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

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

1086. Tree Traversals Again (25) PAT甲級

2019-11-14 09:57:25
字體:
來源:轉載
供稿:網友

傳送門

#include<stdio.h>#include<queue>#include<string.h>#include<stack>using namespace std;#define MAX_N 37int inorder[MAX_N],PReorder[MAX_N];typedef struct Node{ int data; Node *lchild,*rchild;}node,*Btree;int n;void create(Btree &bt,int preL,int preR,int inL,int inR){ if(preL>preR){ bt=NULL; return; } bt=new node; bt->data=preorder[preL]; int leftnum; int i; for(i=inL;i<=inR;i++){ if(inorder[i]==preorder[preL]){ leftnum=i-inL; break; } } create(bt->lchild,preL+1,preL+leftnum,inL,i-1); create(bt->rchild,preL+leftnum+1,preR,i+1,inR);}void postorder(Btree root){ static int count=0; if(root==NULL) return ; postorder(root->lchild); postorder(root->rchild); printf("%d",root->data); count++; if(count<n) printf(" ");}int main(){ scanf("%d",&n); char opr[5]; int num; int preIndex=0,inIndex=0; stack<int> s; for(int i=0;i<2*n;i++){ scanf("%s",opr); if(!strcmp(opr,"Push")){ scanf("%d",&num); preorder[preIndex++]=num; s.push(num); } else{ inorder[inIndex++]=s.top(); s.pop(); } } Btree root=NULL; create(root,0,n-1,0,n-1); postorder(root);}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 始兴县| 滨海县| 盐城市| 天台县| 宁乡县| 革吉县| 渝中区| 蒙山县| 凌源市| 清远市| 措勤县| 镇原县| 寿宁县| 潢川县| 泽库县| 志丹县| 洪湖市| 云和县| 望都县| 丰宁| 寻甸| 都匀市| 涡阳县| 丰台区| 宣汉县| 建德市| 临洮县| 东港市| 瓮安县| 仲巴县| 兴海县| 治多县| 青岛市| 白玉县| 梁山县| 海伦市| 乐至县| 西乡县| 大港区| 肥城市| 汉寿县|