0

How to do quick search in Python3?

27th Jun 2019, 2:12 AM
Amit Dubey
Amit Dubey - avatar
5 Respuestas
+ 2
Which code,post here.
27th Jun 2019, 5:11 AM
Maninder $ingh
Maninder $ingh - avatar
+ 2
This is a algorithm which sorts the list in ascending order. Check this here all types of sorting algorithms are explained. https://www.tutorialspoint.com/JUMP_LINK__&&__python__&&__JUMP_LINK/python_sorting_algorithms.htm
29th Jun 2019, 7:22 AM
Maninder $ingh
Maninder $ingh - avatar
+ 1
from random import randint def quicksort(lst, start, end): if start < end: pivot = randint(start, end) # swap with the last element lst[end],lst[pivot] = lst[pivot],lst[end] # partition the list split = partition(lst, start, end) # sort both halves quicksort(lst, start, split-1) quicksort(lst, split+1, end) def partition(lst, start, end): pivot_index = start-1 for index in range(start, end): # compare with pivot if lst[index] < lst[end]: pivot_index = pivot_index + 1 # swap lst[pivot_index],lst[index] = lst[index],lst[pivot_index] # swap with the last element lst[pivot_index+1],lst[end] = lst[end],lst[pivot_index+1] return pivot_index+1 nums = [7,2,5,1,29,6,4,19,11] quicksort(nums,0,len(nums)-1) print(nums)
28th Jun 2019, 7:02 AM
Amit Dubey
Amit Dubey - avatar
+ 1
This code, can you explain it to me? Maninder $ingh
28th Jun 2019, 7:02 AM
Amit Dubey
Amit Dubey - avatar
0
I find it difficult for me to understand the code..
27th Jun 2019, 2:30 AM
Amit Dubey
Amit Dubey - avatar