Done with 3-5 and 3-6 from hw1
Signed-off-by: jmug <u.g.a.mariano@gmail.com>
This commit is contained in:
parent
226956072a
commit
bd50dad69b
1 changed files with 10 additions and 2 deletions
|
|
@ -742,7 +742,12 @@ let rev_t (l : 'a list) : 'a list =
|
|||
evaluates to true or false.
|
||||
*)
|
||||
let rec insert (x : 'a) (l : 'a list) : 'a list =
|
||||
failwith "insert unimplemented"
|
||||
match l with
|
||||
| [] -> [x]
|
||||
| h :: hs ->
|
||||
if x < h then x :: l
|
||||
else if x = h then l
|
||||
else h :: insert x hs
|
||||
|
||||
(*
|
||||
Problem 3-6
|
||||
|
|
@ -752,7 +757,10 @@ let rec insert (x : 'a) (l : 'a list) : 'a list =
|
|||
Hint: you might want to use the insert function that you just defined.
|
||||
*)
|
||||
let rec union (l1 : 'a list) (l2 : 'a list) : 'a list =
|
||||
failwith "union unimplemented"
|
||||
(* Ideally you'd insert the smallest list into the larger one, but I'll go with the simplest implementation here *)
|
||||
match l1 with
|
||||
| [] -> l2
|
||||
| x :: xs -> union xs (insert x l2)
|
||||
|
||||
(******************************************************************************)
|
||||
(* *)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue