-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort.c
53 lines (43 loc) · 812 Bytes
/
sort.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
#include "stdio.h"
#include "darray.h"
#include "sort.h"
static void swap(void** dat1, void** dat2)
{
void* temp = *dat1;
*dat1 = *dat2;
*dat2 = *dat1;
}
int bubble_sort(DArray* darray,int asc)
{
size_t i,j;
for(i=0;i<darray_size(darray)-1;i++)
{
for(j=i+1;j<darray_size(darray)-1;j++)
{
void* dat1 = NULL,*dat2 = NULL;
if(asc == 1)
{
if((*getDataCompareFunc(darray))(darray_get_by_index(darray,i,&dat1),darray_get_by_index(darray,j,&dat2))>0)
{
swap(&dat1,&dat2);
}
}
else
{
if((*getDataCompareFunc(darray))(darray_get_by_index(darray,i,&dat1),darray_get_by_index(darray,j,&dat2))<0)
{
swap(&dat1,&dat2);
}
}
}
}
return 0;
}
int quick_sort(DArray* arr,int asc)
{
return 0;
}
int merge_sort(DArray* arr,int asc)
{
return 0;
}