#define _CRT_SECURE_NO_WARNNINGS
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include<stdarg.h>
#include<time.h>
/*有的头文件是其它函数需要的*/
int compare(const void *, const void *);
void showarry(int a[], int n);
int main()
{
int a[N] = { 1, 5, 65, 34, 6, 7, 76, 45, 43, 45 };
showarry(a,N);
printf("\n");
int b[N];
int * pi;
memcpy(b, a, N * sizeof(int));
qsort(b, N, sizeof(int), compare);
showarry(b, N);
printf("\n");
pi = (int *)malloc(N * sizeof(int));
memcpy(pi, b, N * sizeof(int));
showarry(pi, N);
free(pi);
getchar();
return 0;
}
int compare(const void * p1, const void * p2)
{
const int * a1 = (int *)p1;
const int * a2 = (int *)p2;
if (*a1 < *a2)
return 1;
else if (*a1 == *a2)
return 0;
else
return -1;
}
void showarry(int a[], int n)
{
int index;
for (index = 1; index < n; index++)
{
printf("%d\t", a[index]);
if (index % 4 == 0)
printf("\n");
}
}
2016.09.28 quicksort.c
最新推荐文章于 2024-07-30 00:14:04 发布