Created
April 2, 2020 02:29
-
-
Save ihzarizkyk/c72cf5264ac29697f800265231c2aac7 to your computer and use it in GitHub Desktop.
This file contains 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 partition(arr,low,high): | |
i = low-1 | |
pivot = arr[high] | |
for j in range(low,high): | |
if(arr[j] <= pivot): | |
i = i+1 | |
arr[i],arr[j] = arr[j],arr[i] | |
arr[i+1],arr[high] = arr[high],arr[i+1] | |
return(i+1) | |
def quicksort(arr,low,high): | |
if(low<high): | |
pi = partition(arr,low,high) | |
quicksort(arr,low,pi-1) | |
quicksort(arr,pi+1,high) | |
#Test Code | |
arr = [10,11,23,12,9,1] | |
n = len(arr) | |
quicksort(arr,0,n-1) | |
print("Sorted Array Is :") | |
for i in range(n): | |
print ("%d" %arr[i]) | |
'''Sorted Array Is : | |
1 | |
9 | |
10 | |
11 | |
12 | |
23 | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment