-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathb_tree.c
77 lines (62 loc) · 1.35 KB
/
b_tree.c
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
/*
* @Description:
* @LastEditors: hsjfans
* @Email: [email protected]
* @Date: 2019-04-24 13:07:51
* @LastEditTime: 2019-05-07 18:11:38
*/
#include "include/b_tree.h"
#include <stdlib.h>
struct BTreeNode
{
int num; // the value num in this node
struct BTreeNode *ptr[M]; // the point to child node
Element *elements[M]; // the num of keywords [M/2] =< range < =M
boolean isLeaf; // is leaf or not. the ptr is empty array when the node is leaf,
};
// Recursive make the tree to empty
// clear the b tree
BTree make_empty(BTree t)
{
if (t != NULL)
{
for (int i = 0; i < t->num; i++)
{
make_empty(t->ptr[i]);
}
free(t);
}
return NULL;
}
// find the key
Position find(Element e, BTree t, compare_func cmp)
{
if (t != NULL)
{
int i = 0;
while (i < t->num)
{
int cp = cmp(e, t->elements[i]);
if (cp == 0)
return t;
else if (cp > 0 && !t->isLeaf)
{
return find(e, t->ptr[i], cmp);
}
i++;
}
}
return NULL;
}
Position find_min(BTree t)
{
}
Position find_max(BTree t)
{
}
BTree insert(Element e, BTree t, compare_func cmp)
{
}
BTree remove(Element e, BTree t, compare_func cmp)
{
}