Skip to content

Instantly share code, notes, and snippets.

@syedjafer
Created April 30, 2021 11:29
Show Gist options
  • Select an option

  • Save syedjafer/2cdad9831c153bdf4004808153a989c8 to your computer and use it in GitHub Desktop.

Select an option

Save syedjafer/2cdad9831c153bdf4004808153a989c8 to your computer and use it in GitHub Desktop.
def partition(array, start, end):
pivot = array[end]
partition_index = start
for itr in range(start, end):
if array[itr] < pivot:
array[partition_index], array[itr] = array[itr], array[partition_index]
partition_index += 1
array[partition_index], array[end] = array[end], array[partition_index]
return partition_index
def qsort(array, start, end):
if start < end:
partition_index = partition(array=array, start=start, end=end)
qsort(array, start, partition_index-1)
qsort(array, partition_index+1, end)
array = [3, 8, 6, 2, 4, 7, 8, 5]
qsort(array, 0, len(array)-1)
print(array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment