Skip to content

Commit e7a494f

Browse files
author
dwipam
committed
Fix quick sort
1 parent 09890f7 commit e7a494f

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

practice/quicksort.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def quicksort(a,li,hi):
55
quicksort(a,li,q-1)
66
def partition(a,li,hi):
77
j=li-1
8-
for i in range(len(a))[li:len(a)-1]:
8+
for i in range(len(a))[li:hi]:
99
if a[i] <= a[hi]:
1010
j+=1
1111
t = a[j]
@@ -15,8 +15,7 @@ def partition(a,li,hi):
1515
a[j+1] = a[hi]
1616
a[hi] = t
1717
return j+1
18-
a = [4,2,1,3]
19-
quicksort(a,0,3)
20-
print a
21-
22-
18+
19+
a = [10, 80, 30, 90, 40, 70, 50]
20+
quicksort(a,0,len(a)-1)
21+
print a

0 commit comments

Comments
 (0)