This is a creation in Article, where the information may have evolved or changed.
--all ofthem . Tip:http://blog.csdn.net/zhengqijun_/article/details/53038831 See:https:// Github.com/hunterhug/goalgorithm
# definition
Quick Sort by C. A. R. Hoare was introduced in 1962. Fast sorting is a kind of improvement to bubble sort, adopting a strategy of divide and conquer. # Basic Ideas
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. # step
1. First remove a number from the series as the base number. 2. The partitioning process will place the number of digits above it to the right, less than or equal to its number to the left of it. 3. Repeat the second step for the left and right intervals until there is only one number for each interval.
# implementation
Package Mainimport"FMT"/************************************ * Function Name: quicksort * functions: Fast sorting algorithm * Parameters: * return value: None * Simulation: BEGIN:[]INT{12, 85, 25, 16, 34, 23, ------------>[],12,[25-----------------------------]---->[23 17],25,[95 -------->[16],17,[]---------->[],16,[]------>[34 85],95,[]-------->[],34,[61 85 95]- --------->[49],61,[95]------------>[],49,[]------------>[85],95,[]-------------->[],85,[] Last: []int{12, +, +, +, +,--]*/func quicksort (array []int, Begin, endint, Markstring) { varI, Jint ifBegin <End {i= Begin +1 //Array[begin] As the base number, so start with the benchmark number from array[begin+1]! j = End//Array[end] is the last of the array for { ifI >=J { Break } ifArray[i] >Array[begin] {array[i], Array[j]=Array[j], Array[i] J= J-1 } Else{i= i +1 } } /*after jumping out of the while loop, I = J. * This time the array is divided into two parts--array[begin+1] ~ Array[i-1] < Array[begin] *--and array[i+ 1] ~ Array[end] > Array[begin] * This time the array is divided into two parts, then Array[i] and Array[begin] to compare, determine the location of array[i]. * Finally, Array[i] and Array[begin] Exchange, the sorting of two segments! And so on, until the end i = J does not meet the conditions to exit! */ ifArray[i] >= Array[begin] {//there must be a ">=" to be taken, or an error will occur if the array element is by the same value! i = i-1} Array[begin], Array[i]=Array[i], Array[begin]//FMT. Printf ("%s>sort:%v\n", Mark, Array[begin:end])Fmt. Printf ("%s>%v,%d,%v\n", Mark, array[begin:i], array[i], Array[j:end]) quicksort (array, begin, I, Mark+"--") quicksort (Array, J, end, Mark+"--")}}func Main () {nums:= []int{ A, -, -, -, the, at, the, the, -, A} fmt. Printf ("begin:% #v \ n", Nums)//Indent inMark: ="--"quicksort (Nums,0, Len (nums)-1, Mark) fmt. Printf ("last:% #v \ n", Nums)}