The idea of quick sequencing:
By sorting the sorted data into separate two parts, one part of all data is smaller than the other part of the data, and then the two parts of the data are quickly sorted by this method, the entire sorting process can be recursive, so as to achieve the entire data into an ordered sequence.
Main ideas:
First, from the back of the loop to find a value smaller than the key value, put this value in front of the key, and then start from the front to find a value larger than key;
The code is as follows:
QuickSort.cpp: Defines the entry point of the console application. #include "stdafx.h" #include <iostream>using namespace std;void QuickSort (int a[], int start,int end) {if (start > End) {return; } int i = start; int j = END; int k = A[i]; while (I < J) {while (I < J && A[j] > K)//First find the value of less than K j--; A[i] = a[j];//Find a value less than K, replace A[i] while (i < J && A[i] < K)//from the front to find a value greater than k i++; A[J] = a[i];//found a value greater than K, just a[j] The value has been assigned just the value of a[i];a[j] is now found in the value of greater than K fill} a[j] = k;//last i = j; Assign the value of K to A[i]; QuickSort (A,i+1,end); QuickSort (a,start,i-1);} int _tmain (int argc, _tchar* argv[]) {int a[] = {1,3,5,7,9,2,4,6,8,0}; int len=sizeof (a)/sizeof (A[0])-1; for (int i=0;i<=len;i++) {cout<<a[i]<< ""; } cout<<endl; cout<< "Quick sort after:" <<endl; Len=sizeof (a)/sizeof (A[0])-1; QuickSort (A,0,len); for (int i=0;i <= len;i++) {cout<<a[i]<< ""; } getchar (); return 0;}
Fast sequencing of C + + algorithms