Repository navigation
Expand file tree
/
Copy pathprototype.c
More file actions
133 lines (131 loc) · 3.94 KB
/
Copy pathprototype.c
File metadata and controls
133 lines (131 loc) · 3.94 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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include <stdio.h>
#include <time.h>
#include "orderedList.c"
#include "bpTree.c"
int getOption(){
int option;
printf("%s\n", "[0] Salir");
printf("%s\n", "[1] Imprimir arbol");
printf("%s\n", "[2] Insertar clave");
printf("%s\n", "[3] Eliminar clave");
printf("%s\n", "[4] Eliminar arbol");
printf("%s\n", "[5] Insertar claves (caso 1)");
printf("%s\n", "[6] Insertar claves (caso 2)");
printf("%s\n", "Ingrese la opcion deseada:");
scanf("%i", &option);
return option;
}
int getKey(){
int key;
printf("%s\n", "Ingrese la clave:");
scanf("%i", &key);
return key;
}
void printSpace(unsigned int length){
if(length>0){
printf(" ");
printSpace(length-1);
}
}
void pausePrinting(){
printf("Presione <Enter> para continuar: ... \n");
getchar();
while(getchar()!='\n')
;
}
void printKey(int key, unsigned int space){
printSpace(space);
printf("%i\n", key);
}
void printLeaf(OrderedList* list, unsigned int space){
if(list!=NULL){
printLeaf(list->next, space);
printKey(list->record.key, space);
}
}
void printTree(BpTree tree, unsigned int space);
void printPage(BpTreePage* page, unsigned int space){
if(page->next!=NULL){
printPage(page->next->next, space);
printKey(page->next->key, space);
}
printTree(page->tree, space+1);
}
void printTree(BpTree tree, unsigned int space){
if(tree.leaf)
printLeaf(tree.list, space);
else
printPage(tree.page, space);
}
void printKeys(BpTree root){
system("clear");
clock_t begin = clock();
printTree(root, 0);
clock_t end = clock();
double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("tiempo transcurrido %f\n",time_spent);
pausePrinting();
}
void doOption(int option, BpTree* root){
switch(option){
case 1:
printKeys(*root);
break;
case 2:
bptInsertTree(root, createRecord(getKey(), NULL));
break;
case 3:
bptDelete(root, getKey());
break;
case 4:
bptDeleteAll(root);
break;
case 5:
bptInsertTree(root, createRecord(10, NULL));
bptInsertTree(root, createRecord(27, NULL));
bptInsertTree(root, createRecord(29, NULL));
bptInsertTree(root, createRecord(17, NULL));
bptInsertTree(root, createRecord(25, NULL));
bptInsertTree(root, createRecord(21, NULL));
bptInsertTree(root, createRecord(15, NULL));
bptInsertTree(root, createRecord(31, NULL));
bptInsertTree(root, createRecord(13, NULL));
bptInsertTree(root, createRecord(51, NULL));
bptInsertTree(root, createRecord(20, NULL));
bptInsertTree(root, createRecord(24, NULL));
bptInsertTree(root, createRecord(48, NULL));
bptInsertTree(root, createRecord(19, NULL));
bptInsertTree(root, createRecord(60, NULL));
bptInsertTree(root, createRecord(35, NULL));
bptInsertTree(root, createRecord(66, NULL));
break;
case 6:
bptInsertTree(root, createRecord(68, NULL));
bptInsertTree(root, createRecord(80, NULL));
bptInsertTree(root, createRecord(53, NULL));
bptInsertTree(root, createRecord(10, NULL));
bptInsertTree(root, createRecord(27, NULL));
bptInsertTree(root, createRecord(43, NULL));
bptInsertTree(root, createRecord(21, NULL));
bptInsertTree(root, createRecord(77, NULL));
bptInsertTree(root, createRecord(58, NULL));
bptInsertTree(root, createRecord(63, NULL));
bptInsertTree(root, createRecord(15, NULL));
bptInsertTree(root, createRecord(37, NULL));
bptInsertTree(root, createRecord(41, NULL));
bptInsertTree(root, createRecord(72, NULL));
bptInsertTree(root, createRecord(39, NULL));
bptInsertTree(root, createRecord(95, NULL));
bptInsertTree(root, createRecord(70, NULL));
break;
}
}
int main(int argc, char **argv){
int option;
BpTree root = bptCreateRoot();
printf("%s\n", "Bienvenido al prototipo del proyecto!");
while((option=getOption())!=0)
doOption(option, &root);
bptDeleteAll(&root);
return 1;
}