标签:style blog io color sp for div log bs
1 /** 2 快速排序的原理: 3 左边的数比middle小 4 右边的数比middle大 5 **/ 6 # include<stdio.h> 7 # include<stdlib.h> 8 void sort(int a[],int low,int high) 9 { 10 int m = a[(low+high)/2]; 11 int i = low,j = high; 12 //分割成两个序列 13 do 14 { 15 //左边的序列 16 while(a[i] < m && i < high) 17 i++; 18 //右边的序列 19 while(a[j] > m && j > low) 20 j--; 21 //找出一对进行排序 22 if(i <= j) 23 { 24 int temp = a[i]; 25 a[i] = a[j]; 26 a[j] = temp; 27 i++; 28 j--; 29 } 30 }while(i <= j); 31 // 递归对比分割点元素都小的那个序列进行快速排序 32 if(j > low) 33 sort(a,low,j); 34 // 递归对比分割点元素都大的那个序列进行快速排序 35 if(i < high) 36 sort(a,i,high); 37 } 38 39 int main() 40 { 41 int i; 42 int a[10] = {8,2,3,4,5,6,7,8,9,1}; 43 sort(a,0,10); 44 for(i = 0;i < 10;i++) 45 { 46 printf("%3d",a[i]); 47 } 48 49 }
标签:style blog io color sp for div log bs
原文地址:http://www.cnblogs.com/sxmcACM/p/4170173.html