First, the algorithm description:
1. First, a number is taken from the series as the base number.
2. The partitioning process, which puts the number of large numbers on its right, is less than or equal to its number to the left.
3. Repeat the second step for the left and right intervals until there is only one number for each interval.
Second, Python quick sort code
Copy the 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:
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]