-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryTree.cpp
More file actions
59 lines (46 loc) · 793 Bytes
/
BinaryTree.cpp
File metadata and controls
59 lines (46 loc) · 793 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 <iostream>
using namespace std;
#include<cstdlib>
#include<ctime>
int randomInt();
struct root{
int num;
root *left;
root *right;
root(int val): num(val), left(nullptr), right(nullptr){}
};
int count = 0;
int main() {
bool larger = false;
root roo(randomInt());
int c = 1;
for(int i =0; i<2; i++){\
int r = randomInt();
root n(r);
if(r>(roo.num)){
roo.right = &n;
larger = true;
}
else
roo.left = &n;
}
cout<<roo.num<<endl;
if (larger == true)
cout<<roo.right->num<<endl;
else
cout<<roo.left->num<<endl;
return 0;
}
int randomInt(){
int a = 0;
if (count == 0){
unsigned seed = time(0);
srand(seed);
a = rand() % 5000;
}
else{
a = rand() % 5000;
}
count++;
return(a);
}