-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathm_way_tree.cpp
More file actions
65 lines (48 loc) · 1.19 KB
/
Copy pathm_way_tree.cpp
File metadata and controls
65 lines (48 loc) · 1.19 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
#include<iostream>
using namespace std;
// order m ----> m-1 elements and m children
const int MAX = 10;
const int INT_MIN = -1000000;
struct node{
int count;
int value[MAX -1];
struct node *child[MAX];
bool isLeaf = true;
node(){
count = 0;
for(int i=0;i<MAX;i++){
child[i] = nullptr;
if(i!=MAX-1){
value[i] = INT_MIN;
}
}
}
bool search(int val,struct node *n){
struct node * temp = nullptr;
if(n->value[0]>val) {
temp = n->child[0];
}
if(val>n->value[MAX-2]){
temp = n->child[MAX-2];
}
for(int i=0;i<MAX-1;i++){
if(n->value[i]==val){
return true;
}
if(i!=MAX-2){
if(val>n->value[i]&& val<n->value[i+1]){
temp = n->child[i+1];
}
}
}
if(n->isLeaf){
return false;
}
bool ans = search(val,temp);
return ans;
}
};
int main(int argc, char const *argv[])
{
return 0;
}