Question: Please finish below functions in Ocaml: (* Partion list l around elt. Return a tuple consisting of all elements before elt and all elements after

Please finish below functions in Ocaml:

(* Partion list l around elt. Return a tuple consisting of all elements before elt and all elements after elt. *) let pivot (cmp : 'a->'a->bool) (elt :'a) (l:'a list) : 'a list * 'a list = (* TODO, replace ([],[]) *) ([], [])

-

(* The simple implementation of quicksort recurses on the two sublists and appends the sorted results. *) let rec quicksort_simple (cmp : 'a->'a->bool) (l : 'a list) : 'a list = (* TODO, replace l *) l

-

(* The better implementation of quicksort elides the append by passing a "tail" list to recursive calls. Sorted results are directly cons'ed onto the tail, avoiding the need for an extra append. *) let quicksort_better (cmp : 'a->'a->bool) (l : 'a list) : 'a list = let rec f (cmp : 'a->'a->bool) (l : 'a list) (r : 'a list) : 'a list = (* r is the tail: everything that must come after l in the sorted list. Passing r to f saves us from having to append sorted lists. *) (* TODO, replace l @ r *) l @ r in f cmp l []

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!