Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
learn-thread-rust
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nawasan Wisitsingkhon
learn-thread-rust
Commits
1ad26fb8
Commit
1ad26fb8
authored
Mar 13, 2024
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add python
parents
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
0 deletions
+37
-0
main.py
main.py
+37
-0
No files found.
main.py
0 → 100644
View file @
1ad26fb8
import
random
import
datetime
def
quick_sort_node
(
arr
:
list
,
st
:
int
,
ed
:
int
)
->
list
:
k
=
st
-
1
for
i
in
range
(
st
,
ed
):
if
arr
[
i
]
<=
arr
[
ed
-
1
]:
k
+=
1
arr
[
i
],
arr
[
k
]
=
arr
[
k
],
arr
[
i
]
len2
=
ed
-
k
-
1
result
=
[]
result
.
append
([
st
,
k
]
if
k
>
1
else
[
0
,
0
])
result
.
append
([
k
+
1
,
ed
]
if
k
>
1
else
[
0
,
0
])
return
result
def
quick_sort_linear
(
arr
:
list
,
init_work
:
list
):
while
len
(
init_work
):
w
=
init_work
.
pop
()
if
w
[
0
]
==
w
[
1
]:
continue
[
r1
,
r2
]
=
quick_sort_node
(
arr
,
w
[
0
],
w
[
1
])
init_work
.
append
(
r1
)
init_work
.
append
(
r2
)
def
quick_sort
(
arr
:
list
):
quick_sort_linear
(
arr
,
[[
0
,
len
(
arr
)]])
ARR_LEN
=
2
_000_000
arr
=
[
None
]
*
ARR_LEN
for
i
in
range
(
ARR_LEN
):
arr
[
i
]
=
random
.
randint
(
0
,
255
)
s1
=
(
datetime
.
datetime
.
now
())
quick_sort
(
arr
)
s2
=
(
datetime
.
datetime
.
now
())
print
(
s2
-
s1
)
# print(arr)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment