-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
77 lines (71 loc) · 1.36 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "Heap.h"
#define TRUE 0
#define FALSE 1
#define MAX_SIZE 20
int main(void)
{
int i;
Element arr[7] = { 2, 63, 28, 48, 5, 89, 6 };
Heap* myHeap;
myHeap = createHeap(MAX_SIZE);
myHeap->heapAry = arr;
myHeap->size = 7;
buildHeap(myHeap);
for (i = 0; i < myHeap->size; i++)
{
printf("%d ", myHeap->heapAry[i]);
}
printf("\n");
int choice = 0;
Element data = 0;
while (1)
{
printf("\nOption\n");
printf("1. Insert\n");
printf("2. Delete\n");
printf("3. Destroy\n");
printf("--------------------\n");
printf("What do you want? : ");
scanf_s("%d", &choice);
switch (choice)
{
case 1:
{
printf("Element : ");
scanf_s("%d", &data);
InsertHeap(myHeap, data);
for (i = 0; i < myHeap->size; i++)
{
printf("%d ", myHeap->heapAry[i]);
}
printf("\n");
break;
}
case 2 :
{
printf("Data : ");
scanf_s("%d", &data);
if (deleteHeap(myHeap, data) == FALSE)
{
printf("Delete failed\n");
}
for (i = 0; i < myHeap->size; i++)
{
printf("%d ", myHeap->heapAry[i]);
}
printf("\n");
break;
}
case 3 :
if (heapDestroy(myHeap))
{
printf("Destroy success\n");
}
else
printf("Destory failed\n");
}
}
}