Commit 252c4068 authored by Taddeus Kroes's avatar Taddeus Kroes

funclang series4: Source code cleanup.

parent 18b75311
......@@ -11,6 +11,7 @@ type expr =
| Id of string
| Const of const
(* Test function that returns converts a typed expression to a string *)
let rec eval_expr =
let eval_bin_op =
let eval_arith_op = function
......
......@@ -3,24 +3,23 @@ open List
(* Sort a list l using the quicksort algorithm *)
let rec quickSort (l : int list) =
match l with
| ([] | [_]) -> l
([] | [_]) -> l
| pivot::rest ->
let cmp x = x < pivot in
let low, high = partition cmp rest in
quickSort low @ pivot :: quickSort high
;;
(* 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
([] | [_]) -> l
| _ ->
let rec merge a b =
match a with
| [] -> b
[] -> b
| ha::ta -> match b with
| [] -> a
[] -> a
| hb::tb -> if ha < hb then ha::(merge ta b)
else hb::(merge a tb)
in
......@@ -30,10 +29,9 @@ let rec mergeSort (l : int list) =
(left, right)
else
match left with
| [] -> (left, right)
[] -> (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)
;;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment