Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created January 28, 2021 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/407cd69b788e9b912110e2eded43bf66 to your computer and use it in GitHub Desktop.
Save amankharwal/407cd69b788e9b912110e2eded43bf66 to your computer and use it in GitHub Desktop.
def partition(input_list,low,high):
i = (low - 1)
item = input_list[high]
for j in range(low, high):
if input_list[j] <= item:
i = i + 1
input_list[i], input_list[j] = input_list[j], input_list[i]
input_list[i+1],input_list[high] = input_list[high],input_list[i+1]
return (i+1)
def quickSort(input_list, low, high):
if low < high:
partition_index = partition(input_list,low,high)
quickSort(input_list, low, partition_index - 1)
quickSort(input_list, partition_index + 1, high)
input_l = [9, 3, 5, 2, 6, 8, 6, 1, 3]
list_length = len(input_l)
quickSort(input_l, 0, list_length -1)
print(input_l)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment