/* * ===================================================================================== * * Filename: QuickSort.c * * Description: * * Version: 1.0 * Created: 2014年06月11日 21时30分51秒 * Revision: none * Compiler: gcc * * Author: Wenxian Ni (Hello World~), niwenxianq@qq.com * Organization: AMS/ICT * * ===================================================================================== */ #include<stdio.h> void swap(int *p, int *q) { int temp = *p; *p = *q; *q = temp; } int GetPos(int *p, int start, int end) { int posData = *(p+start); while(start<end) { while(start<end&&*(p+end)>=posData) end--; if(end!=start) { *(p+start) = *(p+end); start++; while(start<end&&*(p+start)<=posData) start++; if(start!=end) { *(p+end) = *(p+start); end--; } } } *(p+end) = posData; return end; } void QuickSort(int *p, int start, int end) { if(start >= end) return ; int pos = GetPos(p, start, end); QuickSort(p, start, pos-1); QuickSort(p, pos+1, end); return ; } int main() { int a[10]; int n; int i; while(~scanf("%d",&n)) { for(i=0;i<n;i++) scanf("%d",&a[i]); QuickSort(a,0,n-1); for(i=0;i<n;i++) printf("%d ",a[i]); } return 0; }