Skip to content

Commit 400dc39

Browse files
authored
Create quicksort
1 parent 58d8f83 commit 400dc39

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

DS-using-python/quicksort

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def quicksort(seq):
2+
quicksortsec(seq, 0, len(seq)-1)
3+
4+
5+
def quicksortsec(seq, p, r):
6+
if p < r:
7+
q = partition(seq, p, r)
8+
quicksortsec(seq, p, q-1)
9+
quicksortsec(seq, q+1, r)
10+
11+
def partition(seq, p, r):
12+
key = seq[r]
13+
i = p-1
14+
j = p
15+
while j <= r-1 and j >= p:
16+
if seq[j] <= key:
17+
i = i+1
18+
seq[i], seq[j] = seq[j], seq[i]
19+
j += 1
20+
seq[i+1], seq[r] = seq[r], seq[i+1]
21+
print(i+1)
22+
return i+1
23+
24+
L = [2, 8, 7, 1, 3, 5, 6, 4]
25+
quicksort(L)
26+
print(L)

0 commit comments

Comments
 (0)