Skip to content

Instantly share code, notes, and snippets.

@rishi93
Created September 23, 2015 06:07
Show Gist options
  • Save rishi93/da3a2c60f53df77b9554 to your computer and use it in GitHub Desktop.
Save rishi93/da3a2c60f53df77b9554 to your computer and use it in GitHub Desktop.
Quicksort in Place
def quicksort(arr,start,stop):
if stop > start:
left = start
right = stop
pivot = arr[start]
while left <= right:
while arr[left] < pivot:
left += 1
while arr[right] > pivot:
right -= 1
if left <= right:
arr[left],arr[right] = arr[right],arr[left]
left += 1
right -= 1
quicksort(arr,start,right)
quicksort(arr,left,stop)
arr = [4,2,1,3,5,6]
quicksort(arr,0,len(arr)-1)
print(arr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment