69,371
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
int compare (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
int main(int argc, char** argv)
{
int arr[] = {12,7,13,6,24,22,8,9,20,18};
int i = 0;
qsort(arr, sizeof(arr)/sizeof(int), sizeof(int), compare);
for(;
i < sizeof(arr)/sizeof(int);
i++)
{
printf("%d\n",arr[i]);
}
return 0;
}
#include <stdio.h>
#define SUB_SEQU_LEN 3
void quicksort(int array[],int start,int end)
{
if ( start >= end )
return;
int low = start,high = end;
int pivot = array[low];
if ( high - low >= SUB_SEQU_LEN )
printf("%d\r\n",pivot);
while(low < high)
{
while(low < high && array[high] > pivot)
high -= 1;
array[low] = array[high];
while(low < high && array[low] < pivot)
low += 1;
array[high] = array[low];
}
array[low] = pivot;
if ( low > start )
quicksort(array,start,low - 1);
if ( high < end )
quicksort(array,high + 1,end);
}
int main()
{
int array[] = {12,7,13,6,24,22,8,9,20,18};
quicksort(array,0,sizeof(array)/sizeof(int) - 1);
}