Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita7c77fa

Browse files
authored
Create quicksort.py
Quick and dirty implementation of a quicksort algorithm
1 parent334a054 commita7c77fa

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

‎allalgorithms/sorting/quicksort.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
defpartition(xs,start,end):
2+
follower=leader=start
3+
whileleader<end:
4+
ifxs[leader]<=xs[end]:
5+
xs[follower],xs[leader]=xs[leader],xs[follower]
6+
follower+=1
7+
leader+=1
8+
xs[follower],xs[end]=xs[end],xs[follower]
9+
returnfollower
10+
11+
def_quicksort(xs,start,end):
12+
ifstart>=end:
13+
return
14+
p=partition(xs,start,end)
15+
_quicksort(xs,start,p-1)
16+
_quicksort(xs,p+1,end)
17+
18+
defquicksort(xs):
19+
_quicksort(xs,0,len(xs)-1)
20+
21+
# To use: create a list and send it to quicksort: quicksort(list placed here)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp