forked from githubToLearn/algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindPreOrder.cpp
More file actions
59 lines (55 loc) · 925 Bytes
/
findPreOrder.cpp
File metadata and controls
59 lines (55 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <assert.h>
#include <queue>
#include <vector>
#include<list>
#include <algorithm>
#include<iostream>
#include<math.h>
using namespace std;
#define N 50005
#define Inf 0x3f3f3f3f
int mid[N];
int post[N];
void findPre(int m[],int p[],int len){
if(len==0){
return ;
}
int index = -1;
for(int i=0;i<len;i++){
if(m[i]==p[len-1]){
index = i;
break;
}
}
cout<<m[index]<<" ";
findPre(m,p,index);
findPre(m+index+1,p+index,len-index-1);
return;
}
int main() {
int len = 0;
int d;
while(cin>>d){
mid[len] = d;
len++;
char ch = cin.get(); //Äܹ»½ÓÊÕ¿Õ¸ñºÍ»»Ðзû
if(ch=='\n'){
break;
}
}
len = 0;
while(cin>>d){
post[len] = d;
len++;
char ch = cin.get();
if(ch=='\n'){
break;
}
}
findPre(mid,post,len);
return 0;
}