-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathmain.cpp
85 lines (70 loc) · 2.49 KB
/
main.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
#include <stdio.h>
#include <stdlib.h>
#include "BTree.h"
#include "BPlusTree.h"
#include "Context.h"
int main()
{
/*************************************直接调用B B+ 的调度使用****************************************/
/************************************* Direct call B + B method ****************************************/
BTree bt;
BPlusTree bpt;
int arr[] = {18, 31, 12, 10, 15, 48, 45, 47, 50, 52, 23, 30, 20};
for(int i = 0; i < sizeof(arr) / sizeof(int); i++) {
bt.insert(arr[i]);
bpt.insert(arr[i]);
}
printf("no delete data:\n");
printf("display about B-Tree:\n");
bt.level_display();
bt.inorder_print();
printf("\n\n");
printf("display about B+ Tree:\n");
bt.level_display();
bt.inorder_print();
printf("\n");
bpt.linear_print();
printf("\n");
bt.NodeNum_print();
bpt.NodeNum_print();
printf("delete data...\n");
int todel[] = {15, 18, 23, 30, 31, 52, 50};
for(int i = 0; i < sizeof(todel) / sizeof(int); i++) {
printf("after delete %d\n", todel[i]);
bt.del(todel[i]);
bpt.del(todel[i]);
}
bt.NodeNum_print();
bpt.NodeNum_print();
printf("\n\ndelete after data:\n");
printf("display about B-Tree:\n");
bt.level_display();
bt.inorder_print();
printf("\n\n");
printf("display about B+ Tree:\n");
bpt.level_display();
bpt.inorder_print();
printf("\n");
bpt.linear_print();
printf("\n");
/***************************************************************************************************/
/***************************************************************************************************/
/************************************* 用策略方法的调用B ****************************************/
/************************************* strategy pattern method ****************************************/
printf("strategy method start\n");
//“具体策略类”只在定义多个“调度类”时使用
Context *Context_A=new Context(new BTree()),
*Context_B=new Context(new BPlusTree());
//调用方法,只通过“调度类”实现,算法之间的差异已被屏蔽
int arrnum[] = {10, 2, 3, 4, 5, 9, 8, 7, 6,1};
for(int i = 0; i < sizeof(arrnum) / sizeof(int); i++) {
Context_A->Insert(arrnum[i]);
Context_B->Insert(arrnum[i]);
}
Context_A->Inorder_Print();
printf("\n\n");
Context_B->LevelDisplay();
/***************************************************************************************************/
/***************************************************************************************************/
return 0;
}