Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uva
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
uva
Commits
da036965
Commit
da036965
authored
Aug 30, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some whitespace fixes.
parent
c6d73775
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
15 deletions
+9
-15
funclang-taddeus/series4/ass8.ml
funclang-taddeus/series4/ass8.ml
+9
-15
No files found.
funclang-taddeus/series4/ass8.ml
View file @
da036965
open
List
open
List
(* Sort a list l using the quicksort algorithm *)
(* Sort a list l using the quicksort algorithm *)
let
rec
quickSort
(
l
:
int
list
)
=
let
rec
quickSort
(
l
:
int
list
)
=
match
l
with
match
l
with
|
[]
|
[
_
]
->
l
([]
|
[
_
])
->
l
|
pivot
::
rest
->
|
pivot
::
rest
->
let
cmp
x
=
x
<
pivot
in
let
low
,
high
=
partition
(
fun
x
->
x
<
pivot
)
rest
in
let
low
,
high
=
partition
cmp
rest
in
quickSort
low
@
pivot
::
quickSort
high
quickSort
low
@
pivot
::
quickSort
high
(* Sort a list l using the merge sort algorithm *)
(* Sort a list l using the merge sort algorithm *)
let
rec
mergeSort
(
l
:
int
list
)
=
let
rec
mergeSort
(
l
:
int
list
)
=
match
l
with
match
l
with
(* If the list is of length 0 or 1, then it is already sorted *)
(* If the list is of length 0 or 1, then it is already sorted *)
([]
|
[
_
])
->
l
|
[]
|
[
_
]
->
l
|
_
->
|
_
->
let
rec
merge
a
b
=
let
rec
merge
a
b
=
match
a
with
match
a
with
[]
->
b
[]
->
b
|
ha
::
ta
->
match
b
with
|
ha
::
ta
->
match
b
with
[]
->
a
[]
->
a
|
hb
::
tb
->
if
ha
<
hb
then
ha
::
(
merge
ta
b
)
|
hb
::
tb
->
if
ha
<
hb
then
ha
::
(
merge
ta
b
)
else
hb
::
(
merge
a
tb
)
else
hb
::
(
merge
a
tb
)
in
in
let
rec
split
left
right
=
let
rec
split
left
right
=
if
(
length
left
)
-
(
length
right
)
<=
1
then
if
(
length
left
)
-
(
length
right
)
<=
1
then
(* List lengths differ at most 1 element, split is complete *)
(* List lengths differ at most 1 element, split is complete *)
(
left
,
right
)
(
left
,
right
)
...
@@ -32,6 +27,5 @@ let rec mergeSort (l : int list) =
...
@@ -32,6 +27,5 @@ let rec mergeSort (l : int list) =
[]
->
(
left
,
right
)
[]
->
(
left
,
right
)
(* Put one element of left into right list *)
(* Put one element of left into right list *)
|
h
::
t
->
split
t
(
h
::
right
)
|
h
::
t
->
split
t
(
h
::
right
)
in
in
let
left
,
right
=
split
l
[]
let
left
,
right
=
split
l
[]
in
in
merge
(
mergeSort
left
)
(
mergeSort
right
)
merge
(
mergeSort
left
)
(
mergeSort
right
)
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