http://student.zjzk.cn/course_ware/data_structure/web/paixu/paixu8.3.2.1.htm
1、算法思想
快速排序是C.R.A.Hoare于1962年提出的一种划分交换排序。它采用了一种分治的策略,通常称其为分治法(Divide-and-ConquerMethod)。} //QuickSort
附上自己的源码:
#include <stdio.h> #include <stdlib.h> #include <string.h> void QuickSort(int *a,int low,int high); int m_part(int *a,int,int); int main() { //---------------------------------快排quicksort------------- int a[10] = {7,5,9,2,10,6,12,4,5,3}; int n=sizeof(a)/sizeof(int); QuickSort(a,0,n-1); for(int i=0;i<n;i++) { printf("%d ",a[i]); } printf("\n"); system("pause"); return 0; } void QuickSort( int *a ,int low,int high) { if(low<high) { int pov = m_part(a,low,high); QuickSort(a,low,pov); QuickSort(a,pov+1,high); } } int m_part(int *a,int low,int high) { int pov = a[low]; int i=low,j=high; while(i<j) { while( a[j] >= pov && j > i ) j--; a[i] = a[j]; a[j] = pov; while( a[i] <= pov && i < j ) i++; a[j] = a[i]; a[i] = pov; } return i; }