Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
prm2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Mareš
prm2
Commits
a68c9a46
Commit
a68c9a46
authored
5 years ago
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
Rozděl a panuj
parent
8d6ee5c0
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
11-rozdel-a-panuj/mergesort.py
+26
-0
26 additions, 0 deletions
11-rozdel-a-panuj/mergesort.py
11-rozdel-a-panuj/quickselect.py
+20
-0
20 additions, 0 deletions
11-rozdel-a-panuj/quickselect.py
11-rozdel-a-panuj/quicksort.py
+12
-0
12 additions, 0 deletions
11-rozdel-a-panuj/quicksort.py
with
58 additions
and
0 deletions
11-rozdel-a-panuj/mergesort.py
0 → 100644
+
26
−
0
View file @
a68c9a46
#!/usr/bin/python3
def
merge
(
x
,
y
):
i
=
j
=
0
out
=
[]
while
i
<
len
(
x
)
and
j
<
len
(
y
):
if
x
[
i
]
<
y
[
j
]:
out
.
append
(
x
[
i
])
i
+=
1
else
:
out
.
append
(
y
[
j
])
j
+=
1
if
i
<
len
(
x
):
out
.
extend
(
x
[
i
:])
if
j
<
len
(
y
):
out
.
extend
(
y
[
j
:])
return
out
def
mergesort
(
x
):
if
len
(
x
)
<=
1
:
return
x
mid
=
len
(
x
)
//
2
return
merge
(
mergesort
(
x
[:
mid
]),
mergesort
(
x
[
mid
:]))
This diff is collapsed.
Click to expand it.
11-rozdel-a-panuj/quickselect.py
0 → 100644
+
20
−
0
View file @
a68c9a46
#!/usr/bin/python3
def
quickselect
(
x
,
k
):
if
len
(
x
)
<=
1
:
return
x
[
0
]
p
=
x
[
len
(
x
)
//
2
]
vlevo
=
[
a
for
a
in
x
if
a
<
p
]
stred
=
[
a
for
a
in
x
if
a
==
p
]
vpravo
=
[
a
for
a
in
x
if
a
>
p
]
a
=
len
(
vlevo
)
b
=
len
(
vlevo
)
+
len
(
stred
)
if
k
<
a
:
return
quickselect
(
vlevo
,
k
)
elif
k
<
b
:
return
p
else
:
return
quickselect
(
vpravo
,
k
-
b
)
This diff is collapsed.
Click to expand it.
11-rozdel-a-panuj/quicksort.py
0 → 100644
+
12
−
0
View file @
a68c9a46
#!/usr/bin/python3
def
quicksort
(
x
):
if
len
(
x
)
<=
1
:
return
x
p
=
x
[
len
(
x
)
//
2
]
vlevo
=
[
a
for
a
in
x
if
a
<
p
]
stred
=
[
a
for
a
in
x
if
a
==
p
]
vpravo
=
[
a
for
a
in
x
if
a
>
p
]
return
quicksort
(
vlevo
)
+
stred
+
quicksort
(
vpravo
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment