python - Having difficulty in implementing QuickSort -


i have been trying implement quicksort 2 days (looks programming skills getting rusty). not know doing wrong. give thought should consult discussion forum.

here code trying implement in python. not giving desired result. can please point out doing wrong?

def quicksort(a,p,r):  if p < r:     pivotindex = partition(a,p,r)     quicksort(a,p,pivotindex-1)     quicksort(a,pivotindex+1,r)     return def partition(a,p,r):  m = a[p] = p+1 j in range( p+1 , r ):     if a[j] < m:         a[j] , a[i] = a[i] , a[j]         i+=1 a[p], a[i-1] = a[i-1] , a[p] return i-1 

the output test input is:

>>>quicksort([9,8,7,6,5,4,3,2,1],0,9) [1, 3, 5, 6, 7, 4, 8, 2, 9] 

i thankful if me in implementing this.

regards

slicing doesn't return view of original list; makes new list out of data old list. means recursive calls quicksort don't change original list.


Comments