Skip to content

Instantly share code, notes, and snippets.

@ihzarizkyk
Created April 2, 2020 02:29
Show Gist options
  • Save ihzarizkyk/c72cf5264ac29697f800265231c2aac7 to your computer and use it in GitHub Desktop.
Save ihzarizkyk/c72cf5264ac29697f800265231c2aac7 to your computer and use it in GitHub Desktop.
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