Question: Computer Science SML. Please write this in SML, no other language will be accepted. Do not copy and paste from another answer. Problem The goal

 Computer Science SML. Please write this in SML, no other language

Computer Science SML. Please write this in SML, no other language will be accepted. Do not copy and paste from another answer.

Problem The goal of this lab is to implement quicksort in SML. The idea of quicksort was to pick a pivot element p, partition the input in elements smaller than p and elements larger than p, and then recursively sort both parts. As pivot element, we will pick the median of the first, the middle, and the last element in a given list. To implement quicksort, implement the following functions. - A function last (1st) of type 'a list -> 'a which returns the last element of a given list. - A function middle (1st) of type 'a list -> 'a which returns the middle element of a given list. Hint: One way implement this functions is to create a helper function which recursively call itself with one list reduced by one item and the other reduced by two item until the smaller list is empty. - A function median(a, b, c) of type int * int * int -> int which returns the median of the given three elements. - A function partition(1st, p) of type int list * int -> int list * int list that partitions the given list into a list containing all elements smaller than or equal to p and a list p containing all elements larger than p. - A function quicksort(1st) of type int list -> int list which sorts a given list using quicksort and a pivot element as defined above. Do not use any pre-implemented functions of the form List.xyz(...)

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!