Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uva
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
Taddeüs Kroes
uva
Commits
19a4225d
Commit
19a4225d
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
funclang series4: Added assignment 8 implementation.
parent
5b2ec064
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
funclang-taddeus/series4/ass8.ml
+47
-0
47 additions, 0 deletions
funclang-taddeus/series4/ass8.ml
funclang-taddeus/series4/ass9.ml
+1
-0
1 addition, 0 deletions
funclang-taddeus/series4/ass9.ml
with
48 additions
and
0 deletions
funclang-taddeus/series4/ass8.ml
0 → 100644
+
47
−
0
View file @
19a4225d
(* Sort a list l using the quicksort algorithm *)
let
rec
quickSort
(
l
:
int
list
)
=
match
l
with
|
([]
|
[
_
])
->
l
|
pivot
::
rest
->
let
rec
assign
low
high
l
=
match
l
with
(* Assigning elements is done, sort the lower and higher sublists
* individually and concatenate them with the pivot *)
|
[]
->
quickSort
low
@
pivot
::
quickSort
high
(* Assign a list element to the lower or higher sublist,
* depending on its comparison to the pivot *)
|
h
::
t
->
if
h
<=
pivot
then
assign
(
h
::
low
)
high
t
else
assign
low
(
h
::
high
)
t
in
assign
[]
[]
rest
;;
open
List
(* Sort a list l using the merge sort algorithm *)
let
rec
mergeSort
(
l
:
int
list
)
=
match
l
with
(* If the list is of length 0 or 1, then it is already sorted *)
|
([]
|
[
_
])
->
l
|
_
->
let
rec
merge
a
b
=
match
a
with
|
[]
->
b
|
ha
::
ta
->
match
b
with
|
[]
->
a
|
hb
::
tb
->
if
ha
<
hb
then
ha
::
(
merge
ta
b
)
else
hb
::
(
merge
a
tb
)
in
let
rec
split
left
right
=
if
(
length
left
)
-
(
length
right
)
<=
1
then
(* List lengths differ at most 1 element, split is complete *)
(
left
,
right
)
else
match
left
with
|
[]
->
(
left
,
right
)
(* Put one element of left into right list *)
|
h
::
t
->
split
t
(
h
::
right
)
in
let
left
,
right
=
split
l
[]
in
merge
(
mergeSort
left
)
(
mergeSort
right
)
;;
This diff is collapsed.
Click to expand it.
funclang-taddeus/series4/ass9.ml
0 → 100644
+
1
−
0
View file @
19a4225d
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