forked from Phon1209/Competitive_Programming_SourceCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiv.cpp
More file actions
74 lines (64 loc) · 1.09 KB
/
div.cpp
File metadata and controls
74 lines (64 loc) · 1.09 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <bits/stdc++.h>
using namespace std;
class Node {
Node *l, *r;
int val;
public:
Node *createLeft() {
return l = new Node();
}
Node *createRight() {
return r = new Node();
}
Node *getLeft() {
if (l == NULL) createLeft();
printf("L");
return l;
}
Node *getRight() {
if (r == NULL) createRight();
printf("R");
return r;
}
void setValue(int n) {
printf("*\n");
val = n;
}
int getValue() {
return val;
}
};
class Tree {
Node *root;
public:
void insert(int n) {
if (root == NULL) {
root = new Node();
root->setValue(n);
} else {
Node *node = root;
int val;
while (true) {
val = node->getValue();
if (val == 0) {
node->setValue(n);
break;
} else if (val > n) {
node = node->getLeft();
} else {
node = node->getRight();
}
}
}
}
};
int main() {
int N, i, tmp;
Tree *tree = new Tree();
scanf("%d", &N);
for (i = 0; i < N; ++i) {
scanf("%d", &tmp);
tree->insert(tmp);
}
return 0;
}