标签:turn return size 快速排序c语言实现 class bre print blog c语言
#include <stdio.h> void quick_sort(int* a, int n) { if (n < 2) return; int i,j,tmp,k; k = a[n/2]; for(i = 0,j = n-1;;i++,j--) { while(a[i] < k) i++; while(a[j] > k) j--; if(i >= j) break; tmp = a[i]; a[i] = a[j]; a[j] = tmp; } quick_sort(a,i); quick_sort(a+i,n-i); }
int main(int argc, char* argv[])
{
int arr[] = {1,5,7,3,5,7,4,2,6,8,5,3,5,6,8};
int size = sizeof arr / sizeof arr[0];
int i;
for(i = 0; i < size; i++)
{
printf("%d ",arr[i]);
}
quick_sort(arr, size);
printf("\n");
for(i = 0; i < size; i++)
{
printf("%d ",arr[i]);
}
}
标签:turn return size 快速排序c语言实现 class bre print blog c语言
原文地址:http://www.cnblogs.com/AkazaAkari/p/7724815.html