快速排序,gcc亲测能用
#include<stdio.h> void quick_sort(int a[],int left,int right) { int l = left; int r = right; int n = a[left]; if(left >= right) return; while(l<r) { while(l<r && a[r]>=n) r--; a[l]=a[r]; while(l<r && a[l]<=n) l++; a[r]=a[l]; } a[l]=n; quick_sort(a,left,l-1); quick_sort(a,l+1,right); } int main() { int a[5]={5,4,3,2,1}; int i=0; quick_sort(a,0,4); for(i=0; i<5; i++) { printf("%d>>",a[i]); } printf("\n"); return 0; }