-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFifty.cpp
71 lines (71 loc) · 1.32 KB
/
Fifty.cpp
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
#include <iostream>
using namespace std;
struct node {
int data;
node* right;
node* left;
};
node* root;
node* getNewNode(int x)
{
node* temp = new node();
temp->data = x;
temp->right = NULL;
temp->left = NULL;
return temp;
}
void insert(int x) {
if (root == NULL) {
root = getNewNode(x);
}
else{
node* mark;
node* t = root;
while (t != NULL) {
if (t->data > x) {
mark = t;
t = t->left;
}
else
{
mark = t;
t = t->right;
}
}
if (mark->data > x) {
mark->left = getNewNode(x);
}
else
mark->right = getNewNode(x);
}
}
void display(node* t) {
if (t != NULL) {
display(t->left);
std::cout << t->data << ' ';
display(t->right);
}
}
void findMin() {
node* t = root;
while (t->left != NULL) {
t = t->right;
}
std::cout << "The minimum element is " << t->data << '\n';
}
int main(int argc, char const *argv[]) {
insert(4);
insert(5);
insert(3);
insert(7);
insert(12);
insert(90);
insert(11);
insert(8);
insert(13);
insert(15);
display(root);
std::cout << '\n';
findMin();
return 0;
}