The fast sort implemented here is a reference to the pseudo-code in the introduction to the algorithm, although the pseudo-code was previously knocked over, but now the pseudo-code, it is a bit hard to knock yourself. <-_->!!
In particular, the introduction of the algorithm in the fast-line method, and the class is not the same, the main lesson is to use the first two subscript to achieve, and the introduction of the algorithm, mainly from the front to the back, in order to judge, will be less than Privot value all moved to the front of I. Here I refers to the upper bounds of the subscript less than the Privot value.
The source code is as follows:
//===================== "quick Sort" ==================//@ author:zhyh2010//@ date:20150606//@ version:1.0//@ Description://===================== "quick Sort" ==================#include <stdio.h>#include <stdlib.h>#include <time.h>#define NUMintArr[num] = {0};voidInit () {time_t TM; Time (&TM); Srand ((unsigned int) tm);intMax_item = -; for(inti =0; I! = NUM; i++) Arr[i] = rand ()% Max_item;}voidSwapint* PA,int* Pb) {intAA = *PA;intbb = *PB; aa = aa ^ bb; bb = aa ^ bb; aa = aa ^ bb; *PA = AA; *PB = BB;}intPartitionintLowintHigh) {inti = low-1;//mark the upper limit of <= Privot intPrivot = Arr[high]; for(intj = Low; J! = high; J + +) {if(Arr[j] <= privot)//Move the small value to the front of ISwap (&arr[++i], &arr[j]); } Swap (&arr[i +1], &arr[high]);returni +1;}voidDisplayint* arr) { for(inti =0; I! = NUM; i++)printf("%-10d", Arr[i]);printf("\ n");}voidQuickSort (intLowintHigh) {if(Low >= High)return;intMID = partition (low, high); QuickSort (Low, mid-1); QuickSort (Mid +1, high);}voidMain () {init ();printf("Quick sort before \ n"); Display (arr); QuickSort (0, NUM-1);printf("Quick sort after \ n"); Display (arr);}
A method of C implementation for fast sequencing of classical algorithms