-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
92 lines (83 loc) · 2.34 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
#include <stdio.h>
#include <stdlib.h>
#include "bubble_sort.h"
#include "selection_sort.h"
#include "insertion_sort.h"
#include "merge_sort.h"
#include "quick_sort.h"
int intCompare(int* x, int* y)
{
if((*x) <= (*y))
{
//printf("%d is greater than %d\n", *y, *x);
return 1;
}
else
{
//printf("%d is greater than %d\n", *x, *y);
return -1;
}
}
void intSwap(int* x, int* y)
{
int temp = *x;
*x = *y;
*y = temp;
}
int* intNext(int* data, int i)
{
return (data+i);
}
void intCopy(int* x, int* y)
{
//printf("Copied %d\n", *y);
*x = *y;
//printf("After copying %d\n", *x);
}
double* doubleNext(double* data, int i)
{
return (data+i);
}
int doubleCompare(double* x, double *y)
{
//printf("comparing %f, %f", *x, *y);
if((*x) < (*y))
{
return 1;
}
else
return -1;
}
void doubleSwap(double* x, double* y)
{
double temp = *x;
*x = *y;
*y = temp;
}
void doubleCopy(double* x, double* y)
{
*x = *y;
}
int main()
{
int adata[] = {5, 6 , 1, 25, 99, 9, 3,-1 };
double fdata[] = {5.6, 7.8, 1.2, 4.1, 9.9};
//bubble_sort(adata, 7, (int(*)(void*, void*))intCompare,(void(*)(void*,void*))intSwap, (void*(*)(void*, int))intNext);
//bubble_sort(fdata, 5, (int(*)(void*, void*))doubleCompare,(void(*)(void*,void*))doubleSwap,(void*(*)(void*,int))doubleNext);
//selection_sort(adata, 7, (int(*)(void*, void*))intCompare,(void(*)(void*,void*))intSwap, (void*(*)(void*,int))intNext);
//insertion_sort(adata, 8, sizeof(int), (int(*)(void*,void*))intCompare, (void*(*)(void*,int))intNext,(void(*)(void*,void*))intCopy);
//insertion_sort(fdata, 5, sizeof(double), (int(*)(void*,void*))doubleCompare, (void*(*)(void*,int))doubleNext,(void(*)(void*,void*))doubleCopy);
//merge_sort(adata, 8, sizeof(int), (int(*)(void*,void*))intCompare, (void*(*)(void*,int))intNext, (void(*)(void*,void*))intCopy);
merge_sort(fdata, 5, sizeof(double), (int(*)(void*,void*))doubleCompare, (void*(*)(void*,int))doubleNext, (void(*)(void*,void*))doubleCopy);
//quick_sort(adata, 0, 7, sizeof(int), (int(*)(void*, void*))intCompare, (void(*)(void*, void*))intSwap, (void*(*)(void*,int))intNext);
int i;
for(i = 0; i < 8; i++)
{
//printf("%d\t", adata[i]);
}
for(i = 0; i < 5; i++)
{
printf("%f\t", fdata[i]);
}
return 0;
}