In this paper, we describe the application of Python Quick Find algorithm and share it for your reference.
The implementation method is as follows:
Import randomdef partition (List_object,start,end): random_choice = Start #random. Choice (Range (start,end+1) ) #把这里的start改成random () is more efficient x = List_object[random_choice] i = start j = End While True: While List_object[i] < x and I < end: i + = 1 while list_object[j] > x: J-= 1 if I >= j:
break List_object[i],list_object[j] = list_object[j],list_object[i] print list_object #list_ Object[random_choice] = list_object[j] #list_object [j] = Random_choice return jdef quick_sort (List_object, Start,end): If start < end: temp = partition (list_object,start,end) Quick_sort (List_object,start, temp-1) Quick_sort (list_object,temp + 1, end) a_list = [69,65,90,37,92,6,28,54]quick_sort (a_list,0,7) Print A_list
The program test environment is Python2.7.6
The output results are as follows:
[54, 65, 28, 37, 6, 69, 92, 90] [6, 37, 28, 54, 65, 69, 92, 90] [6, 37, 28, 54, 65, 69, 92, 90] [6, 28, 37, 54, 65, 69, 92, 90] [6, 28, 37, 54, 65, 69, 90, 92] [6, 28, 37, 54, 65, 69, 90, 92]
Hopefully this article will help you with Python programming.