<title>Sort Quick Sort</title> Sort Quick Sort
Here are some basic sort of introductions, of course, just for my own personal understanding:-)
The so-called quick sort, in fact, is based on the last numerical value of the array, the others compared to him, than he is bigger, put on the right, smaller than he put on the left. If we define an i =-1, then each time we sweep to find that there is a smaller than the reference , let i+1, and then compare this to the reference small number and the current I corresponding value exchange. Through this we can find that the reference location should be at the i+1 place. Through this, we can only determine where this reference is located.
An introduction to Algorithms
/** createtime:2014-12-23 14:49:21 */#include <stdio.h>int a[10] = {12, 2, 16, 30, 28, 10, 16, 20, 6, 18};void Swap(int I,int J) {int T= A[i]; A[i] = A[j]; A[J] = t; }int Partition(int L,int R) {int I= L-1;int k= A[r]; for(int J= L; J < R; J + +) {if(A[j] < K) {i++; Swap (I, j); }} swap (i+1, R);// exactly in the position of I, from L~i are small a[r] // so the position of A[r] is on the i+1, when A[r] is a well-sequenced returni+1;}void Qsort1(int L,int R) {if(L < R) {int m= Partition (L, R); Qsort1 (L, m-1); Qsort1 (m+1, R); }}int Main(void) {qsort1 (0, 9); for(int I= 0; I < 10; i++) {printf ("%d", A[i]); } printf ("\ n");return0;}
The wording of three tangential direction
/** CREATETIME:2014-11-17 13:24:40 */#include <stdio.h>int a[10] = {1, 454, 634, 34, 3, 3, 2343, 23435, 34, 42};void Swap(int I,int J) {int T= A[i]; A[i] = A[j]; A[J] = t; }void Quick3(int L,int R) {if(L < R) {int LT= L;int GT= R;int I= L + 1;int Key= A[l]; while(I <= GT) {if(A[i] < key) {Swap (i++, lt++); }Else if(A[i] > key) {Swap (I, gt--); }Else{i++; }} quick3 (L, lt-1); Quick3 (gt+1, R); }}int Main(void) {Quick3 (0, 9); for(int I= 0; I < 10; i++) {printf ("%d", A[i]); } printf ("\ n");return0;}
Sort Quick Sort