-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
54 lines (38 loc) · 1.19 KB
/
main.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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "./priorityQueue/priorityQueue.c"
#include "./heap/heap.c"
int main() {
srand(time(NULL));
FILE *heapFile = fopen("./heap/heapFile.txt", "w");
if(!heapFile) {
printf("Failed to open heapFile\n");
return 0;
}
FILE *queueFile = fopen("./priorityQueue/queueFile.txt", "w");
if(!queueFile) {
printf("Failed to open queueFile\n");
return 0;
}
heap *heap = createHeap();
priorityQueue *queue = createPriorityQueue();
int contHeap = 1, contQueue = 1, num, max;
printf("Quantidade de numeros inseridos > ");
scanf("%d", &max);
fprintf(heapFile, "num, cont\n");
fprintf(queueFile, "num, cont\n");
for(int i = 0; i < max; ++i) {
num = rand() % 10000;
queue = enqueuePq(queue, num, &contQueue);
contHeap = enqueueHeap(heap, num);
fprintf(heapFile, "%d,%d\n", num, contHeap);
fprintf(queueFile, "%d,%d\n", num, contQueue);
contQueue = 1;
}
fclose(heapFile);
fclose(queueFile);
destroyHeap(heap);
destroyPriorityQueue(queue);
return 0;
}