-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.cpp
More file actions
29 lines (29 loc) · 635 Bytes
/
.cpp
File metadata and controls
29 lines (29 loc) · 635 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
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
int size, x, root;
pair<int,int> tree[1000000];
int* find(int num, int parent) {
if(num > parent) {
if(tree[parent].Y == 0) return &tree[parent].Y;
return find(num, tree[parent].Y);
}
else if(num < parent) {
if(tree[parent].X == 0) return &tree[parent].X;
return find(num, tree[parent].X);
}
}
void postOrder(int cur) {
if(tree[cur].X) postOrder(tree[cur].X);
if(tree[cur].Y) postOrder(tree[cur].Y);
cout << cur << "\n";
}
int main() {
cin >> root;
while(cin >> x) {
int* address = find(x, root);
*address = x;
}
postOrder(root);
}