First, the algorithm description:
1. First, take a number out of the series as the base number.
2. The partitioning process, which places the number larger than this to its right, is less than or equal to its number on the left.
3. Repeat the second step to the left and right intervals until the interval is only one number.
Second, Python quick sort code
Copy Code code as follows:
#!/usr/bin/python
#-*-Coding:utf-8-*-
Def sub_sort (array,low,high):
key = Array[low]
while low < high:
while low < high and Array[high] >= key:
& nbsp; High-= 1
while low < high and Array[high] < key:
Array[low] = array[ High]
low = 1
Array[high] = Array[low]
array[low] = key
return low
def quick_sort (Array,low,high):
If low < high:
Key_index = Sub_sort (Array,low,high)
Quick_sort (Array,low,key_index)
Quick_sort (Array,key_index+1,high)
if __name__ = = ' __main__ ':
Array = [8,10,9,6,4,16,5,13,26,18,2,45,34,23,1,7,3]
Print array
Quick_sort (Array,0,len (array)-1)
Print array
Results:
[8, 10, 9, 6, 4, 16, 5, 13, 26, 18, 2, 45, 34, 23, 1, 7, 3]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 16, 18, 23, 26, 34, 45]