forked from Firkraag/algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
b_tree_test.py
executable file
·72 lines (70 loc) · 1.25 KB
/
b_tree_test.py
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
#!/usr/bin/env ipython
import b_tree as bt
a = bt.b_tree_node(3, True, 2)
a.key[0] = 'A'
a.key[1] = 'B'
b = bt.b_tree_node(3, True, 3)
b.key[0] = 'D'
b.key[1] = 'E'
b.key[2] = 'F'
c = bt.b_tree_node(3, True, 3)
c.key[0] = 'J'
c.key[1] = 'K'
c.key[2] = 'L'
d = bt.b_tree_node(3, True, 2)
d.key[0] = 'N'
d.key[1] = 'O'
x = bt.b_tree_node(3, True, 3)
x.key[0] = 'Q'
x.key[1] = 'R'
x.key[2] = 'S'
y = bt.b_tree_node(3, True, 2)
y.key[0] = 'U'
y.key[1] = 'V'
z = bt.b_tree_node(3, True, 2)
z.key[0] = 'Y'
z.key[1] = 'Z'
e = bt.b_tree_node(3, False, 3)
e.key[0] = 'C'
e.key[1] = 'G'
e.key[2] = 'M'
e.c[0] = a
e.c[1] = b
e.c[2] = c
e.c[3] = d
v = bt.b_tree_node(3, False, 2)
v.key[0] = 'T'
v.key[1] = 'X'
v.c[0] = x
v.c[1] = y
v.c[2] = z
t = bt.b_tree(3)
t.root.key[0] = 'P'
t.root.c[0] = e
t.root.c[1] = v
t.root.n = 1
t.root.leaf = False
t.root.delete(t, 'F')
t.root.print_child_first()
print
t.root.delete(t, 'M')
t.root.print_child_first()
print
t.root.delete(t, 'G')
t.root.print_child_first()
print
t.root.delete(t, 'D')
t.root.print_child_first()
print
t.root.delete(t, 'B')
t.root.print_child_first()
print
t.root.delete(t, 'C')
t.root.print_child_first()
print
t.root.delete(t, 'P')
t.root.print_child_first()
print
t.root.delete(t, 'V')
t.root.print_child_first()
print