-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminimum_ele_BST.cpp
More file actions
71 lines (68 loc) · 1.4 KB
/
minimum_ele_BST.cpp
File metadata and controls
71 lines (68 loc) · 1.4 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
#include<bits/stdc++.h>
using namespace std;
struct node
{
int data;
struct node* left;
struct node* right;
};
struct node* newNode(int data)
{
struct node* node = (struct node*)malloc(sizeof(struct node));
node->data = data;
node->left = NULL;
node->right = NULL;
return(node);
}
struct node* insert(struct node* node, int data)
{
if(node == NULL)return(newNode(data));
else
{
if (data <= node->data)node->left = insert(node->left, data);
else node->right = insert(node->right, data);
return node;
}
}
int minValue(struct node* root);
int main()
{
int t;
cin>>t;
while(t--)
{
int n, tmp;
cin>>n>>tmp;
struct node* root = NULL;
root = insert(root, tmp);
n--;
while(n--){
cin>>tmp;
insert(root, tmp);
}
cout<<minValue(root)<<endl;
}
return 0;
}
/*Please note that it's Function problem i.e.
you need to write your solution in the form of Function(s) only.
Driver Code to call/invoke your function is mentioned above.*/
/*
Structure of the node of the binary search tree is as
struct node
{
int data;
struct node* left;
struct node* right;
};
*/
// your task is to complete the below function
int minValue(struct node* root)
{
node* temp = root;
while(temp->left){
temp = temp->left;
}
return temp->data;
// Code here
}