-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5639.cpp
More file actions
39 lines (32 loc) · 772 Bytes
/
5639.cpp
File metadata and controls
39 lines (32 loc) · 772 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
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int tree[1000050][2];
void build(int cur, int node){
if(cur < node){
if(tree[node][0] == 0) tree[node][0] = cur;
else build(cur, tree[node][0]);
}
else if(cur > node){
if(tree[node][1] == 0) tree[node][1] = cur;
else build(cur, tree[node][1]);
}
}
void postorder(int u){
if(tree[u][0] != 0) postorder(tree[u][0]);
if(tree[u][1] != 0) postorder(tree[u][1]);
cout << u << '\n';
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int root; cin >> root;
while(1){
int n; cin >> n;
if(cin.eof() == true) break;
build(n, root);
}
postorder(root);
}