Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AP-belkacemi-melissa
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Melissa Belkacemi
AP-belkacemi-melissa
Commits
c242f300
Commit
c242f300
authored
1 year ago
by
Belkacemi Melissa
Browse files
Options
Downloads
Patches
Plain Diff
split
parent
831709e7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
TP9/tri-fusion/merge_sort.py
+24
-3
24 additions, 3 deletions
TP9/tri-fusion/merge_sort.py
with
24 additions
and
3 deletions
TP9/tri-fusion/merge_sort.py
+
24
−
3
View file @
c242f300
...
...
@@ -61,7 +61,6 @@ def length(li: ApLst) -> int:
else
:
return
1
+
length
(
li
.
tail
())
length
(
ApLst
(
3
,
ApLst
(
1
,
ApLst
(
4
,
ApLst
()))))
def
native_to_list
(
li
:
list
[
T
])
->
ApLst
:
"""
...
...
@@ -143,7 +142,15 @@ def split(l: ApLst) -> tuple[ApLst, ApLst]:
$$$ all(k in l for k in l3)
True
"""
...
if
length
(
l
)
>=
2
:
l1
=
ApLst
(
l
.
head
(),
split
((
l
.
tail
()).
tail
())[
0
])
l2
=
ApLst
((
l
.
tail
()).
head
(),
split
((
l
.
tail
()).
tail
())[
1
])
return
(
l1
,
l2
)
if
l
.
is_empty
():
return
(
ApLst
(),
ApLst
())
if
length
(
l
)
==
1
:
return
(
ApLst
(
l
.
head
(),
ApLst
()),
ApLst
())
def
merge
(
l1
:
ApLst
,
l2
:
ApLst
,
...
...
@@ -158,7 +165,21 @@ def merge(l1: ApLst, l2: ApLst,
$$$ list_to_native(merge(native_to_list([1, 3, 4, 9]), native_to_list([1, 2, 5])))
[1, 1, 2, 3, 4, 5, 9]
"""
...
res
=
[]
while
not
(
l1
.
is_empty
()
or
l2
.
is_empty
()):
if
comp
(
l1
.
head
(),
l2
.
head
())
<
0
:
res
.
append
(
l1
.
head
())
l1
=
l1
.
tail
()
else
:
res
.
append
(
l2
.
head
())
l2
=
l2
.
tail
()
while
not
l1
.
is_empty
():
res
.
append
(
l1
.
head
())
l1
=
l1
.
tail
()
while
not
l2
.
is_empty
():
res
.
append
(
l2
.
head
())
l2
=
l2
.
tail
()
return
native_to_list
(
res
)
def
mergesort
(
l
:
ApLst
,
comp
:
Callable
[[
T
,
T
],
int
]
=
compare
)
->
ApLst
:
...
...
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