-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path215.cpp
90 lines (65 loc) · 1.65 KB
/
215.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// { Driver Code Starts
// Initial Template for C
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#define N 1000000
struct Node {
int data;
struct Node *right;
struct Node *left;
};
struct Node *createNewNode(int value) {
struct Node *temp = (struct Node *)malloc(sizeof(struct Node *));
temp->data = value;
temp->left = temp->right = NULL;
return temp;
}
struct Node *insert(struct Node *tree, int val) {
if (tree == NULL) {
return createNewNode(val);
}
if (val < tree->data) {
tree->left = insert(tree->left, val);
} else if (val > tree->data) {
tree->right = insert(tree->right, val);
}
return tree;
}
struct Node *convert_str_to_num(char str[]) {
char *token = strtok(str, " ");
struct Node *root = NULL;
while (token != NULL) {
int num = atoi(token);
if (num != 0) {
root = insert(root, num);
}
token = strtok(NULL, " ");
}
return root;
}
// } Driver Code Ends
// User function Template for C
int minValue(struct Node *root) {
if(!root) return -1;
if(root->left==NULL) return root->data;
minValue(root->left);
}
// { Driver Code Starts.
int main() {
int t;
scanf("%d", &t);
while (t--) {
while ((getchar()) != '\n')
;
char str[N];
scanf("%[^\n]s", str);
struct Node *root = NULL;
root = convert_str_to_num(str);
int ans = minValue(root);
printf("%d\n", ans);
}
return 0;
}
// } Driver Code Ends