Created
September 23, 2015 06:07
-
-
Save rishi93/da3a2c60f53df77b9554 to your computer and use it in GitHub Desktop.
Quicksort in Place
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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