版权声明:本文为博主原创文章,转载请注明出处http://blog.csdn.net/u013132758。 https://blog.csdn.net/u013132758/article/details/52106781
排序问题是我们算法中最常遇到的问题,也是最基础的问题。排序算法主要有8大算法。今天主要介绍快速排序。
一言不和我们就先上代码:
</pre><pre code_snippet_id="1804909" snippet_file_name="blog_20160803_1_2266677" name="code" class="cpp">
<pre code_snippet_id="1804909" snippet_file_name="blog_20160803_1_2266677" name="code" class="cpp">#include <stdio.h>
int Split(int *A,int low, int high);void quick_sort (int *A,int low,int high);int main(int argc, const char * argv[]) { int A[6] = {11,5,3,4,15,6}; quick_sort(A, 0, 5); printf("%d\n",A[0]); printf("%d\n",A[1]); printf("%d\n",A[2]); printf("%d\n",A[3]); printf("%d\n",A[4]); printf("%d\n",A[5]); return 0;}int Split(int *A,int low, int high){ int x,i,j,index; x = A[low]; i = low; for (j =i+1; j<= high ;j++) { if(A[j] < x) { i++; if( i != j){ index =A[i]; A[i] = A[j]; A[j] = index; } } } x = A[low]; A[low] = A[i]; A[i] = x; return i;}void quick_sort (int *A,int low,int high){ int num; if (high <= low) { return ; } num = Split(A,low,high); quick_sort(A, low, num-1); quick_sort(A, num+1, high);}
未完,待续。。。。。。
</pre><pre code_snippet_id="1804909" snippet_file_name="blog_20160803_1_2266677" name="code" class="cpp">