Skip to content

Instantly share code, notes, and snippets.

@chirag-shinde
Created July 12, 2020 18:08
Show Gist options
  • Save chirag-shinde/0a03b2239c47d42627867092c6ca76c0 to your computer and use it in GitHub Desktop.
Save chirag-shinde/0a03b2239c47d42627867092c6ca76c0 to your computer and use it in GitHub Desktop.
def quick_sort(arr,start, end):
if start < end:
pivot = partition(arr, start, end)
quick_sort(arr, start, pivot - 1)
quick_sort(arr, pivot + 1, end)
def partition(arr, start, end):
element = arr[start]
i = start
for j in range(start + 1, end):
if arr[j] < element:
i += 1
arr[i], arr[j] = arr[j], arr[i]
arr[start], arr[i] = arr[i], arr[start]
return i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment