FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm-pattern-python/basic_algorithm/quicksort.py at master · dashidhy/algorithm-pattern-python · GitHub
dashidhy
/
algorithm-pattern-python
Public
forked from
greyireland/algorithm-pattern
Notifications
You must be signed in to change notification settings
Fork
219
Star
780
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm-pattern-python
/
basic_algorithm
/
quicksort.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
32 lines (23 loc) · 790 Bytes
Breadcrumbs
algorithm-pattern-python
/
basic_algorithm
/
quicksort.py
Copy path
File metadata and controls
32 lines (23 loc) · 790 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import
random
def
partition
(
nums
,
left
,
right
):
if
left
>=
right
:
return
pivot_idx
=
random
.
randint
(
left
,
right
)
pivot
=
nums
[
pivot_idx
]
nums
[
right
],
nums
[
pivot_idx
]
=
nums
[
pivot_idx
],
nums
[
right
]
partition_idx
=
left
for
i
in
range
(
left
,
right
):
if
nums
[
i
]
<
pivot
:
nums
[
partition_idx
],
nums
[
i
]
=
nums
[
i
],
nums
[
partition_idx
]
partition_idx
+=
1
nums
[
right
],
nums
[
partition_idx
]
=
nums
[
partition_idx
],
nums
[
right
]
partition
(
nums
,
partition_idx
+
1
,
right
)
partition
(
nums
,
left
,
partition_idx
-
1
)
return
def
quicksort
(
A
):
partition
(
A
,
0
,
len
(
A
)
-
1
)
return
A
if
__name__
==
'__main__'
:
a
=
[
7
,
6
,
8
,
5
,
2
,
1
,
3
,
4
,
0
,
9
,
10
]
print
(
a
)
print
(
quicksort
(
a
))
Back
|
FazBrowse Home
|
New Git URL