The fast line should be the most important one in the sort of data structure, including the thought of Patition, and the thought of division and treatment of the whole behind, all have great reference to solve the practical problem. Fast sorting is a method of exchanging sorts, which means that if two are the same number, the two may swap positions after the fast.
1. First look at the partition function, functions named partition (data, L, R), in Data[l,r] find the number of position I, so that I left the number is less than that number, I to the right of the number is greater than the number, and return position I
def partition (data, L, r): i = LJ = Rx = data[i]while i<j:while i<j&data[j]>x:j = 1if I<j:data[i] = data[j ]i + = 1while i<j&data[i]<x:i + 1if i<j:data[j] = data[i]j-= 1data[i] = Xreturn I
2. Then the entire array is divided into recursive operation can be
def qsort (data, L, R): If L<R:I = partition (data, L, R) qsort (data, L, i-1) qsort (data, i+1, R) def quicksort (data): Qsort (d ATA, 0, Len (data)-1)
Fast sequencing of data structures