Skip to content

Instantly share code, notes, and snippets.

@syedjafer
Last active April 30, 2021 11:43
Show Gist options
  • Select an option

  • Save syedjafer/7a4b2d0405bbbe6367494a382edc8f80 to your computer and use it in GitHub Desktop.

Select an option

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