-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
104 lines (82 loc) · 2.29 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
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
//
// main.c
// Sorting
//
// Created by 세연 on 2022/04/10.
//
#include "sort.h"
int numOfElements;
Arr* arr;
int main(int argc, const char * argv[]) {
clock_t start, end;
int s, i;
printf("Enter the number of numbers to sort\n:");
scanf("%d", &numOfElements);
arr = (Arr*)malloc(sizeof(Arr)*numOfElements);
initArray(arr);
Heap H;
LIST *list = initList();
for (i = 0; i<numOfElements; i++) {
insertRight(list, rand()%100);
}
LIST *listOfList[numOfElements];
for (i = 0; i < numOfElements; i++) {
listOfList[i] = initList();
}
printf("------------Select a sort algorithm");
printf("\n1.Exchange Sort\n2.Merge Sort\n3.Quick Sort\n4.Heap Sort\n5.Radix Sort\n:");
scanf("%d", &s);
printf("\n------------An array before sorting\n");
switch (s) {
case 1 ... 3:
printArray(arr, numOfElements);
break;
case 4:
printArray(arr, numOfElements);
H.arr = arr;
H.heapSize = numOfElements-1;
break;
case 5:
printList(list);
break;
}
start = clock();
switch (s) {
case 1:
ExchangeSort(arr);
printf("\n------------The result of Exchange Sort\n");
break;
case 2:
MergeSort(arr, numOfElements);
printf("\n------------The result of Merge Sort\n");
break;
case 3:
QuickSort(0, numOfElements);
printf("\n------------The result of Quick Sort\n");
break;
case 4:
HeapSort(numOfElements-1, &H);
printf("\n------------The result of Heap Sort\n");
break;
case 5:
RadixSort(list, listOfList);
printf("------------The result of Radix Sort\n");
break;
}
end = clock();
switch (s) {
case 1 ... 4:
printArray(arr, numOfElements);
break;
case 5:
printList(list);
break;
}
printf("\nThe time is %lf\n\n", (double)(end-start));
free(arr);
freeList(list);
for (i = 0; i < numOfElements; i++) {
freeList(listOfList[i]);
}
return 0;
}