Created
October 28, 2015 18:06
-
-
Save akshaydk/5b6818e13b4e38245e29 to your computer and use it in GitHub Desktop.
#PA2-Q1
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 quick_sort(A,low,high): | |
if low<high: | |
i=low+1 | |
pivot=low | |
print 'pivot=', A[pivot] | |
left=right=count=0 | |
for j in range(low+1,high): | |
# print 'i=',i | |
# print 'j=',j | |
count+=1 | |
if A[pivot]>A[j]: | |
swap(A,i,j) | |
i+=1 | |
#print A | |
swap(A,low,i-1) | |
print 'end',A | |
print 'count=',count | |
left=quick_sort(A,low,i-1) | |
right=quick_sort(A,i,high) | |
return left+right+count | |
else: | |
return 0 | |
def swap(A,x,y): | |
temp=A[x] | |
A[x]=A[y] | |
A[y]=temp | |
A=[3,8,2,5,1,4,7,6,10,9] | |
print quick_sort(A,0,len(A)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment