Write an ML function qsort which, given a list of objects l and a comparator fun
ID: 640725 • Letter: W
Question
Write an ML function qsort which, given a list of objects l and a comparator function f (given curry in curry style, f has type ?a right arrow ?a right arrow boot) outputs a sorted version of l in ascending order according to f using the classic quicksort algorithm. Note that we are well aware of the Wikipedia implementation or the other dozen implementations floating on the web. I expect you to write this on your own! Namely, write fun qsort 1 f = ... Revisit the previous question, hut this time, you cannot define the partition from first principles (as a recursive function) nor can you use the List|.partition basis function. The only thing you can use is the higher-order function foldr. fun qsHigh 1f = ...Explanation / Answer
fun qsort (s1, s2) = if size s1 size s2 then size s2 > size s1 else String.map Char.toLower s1 > String.map Char.toLower s2 - val strings = ["Here", "are", "some", "sample", "strings", "to", "be", "sorted"]; val strings = ["Here","are","some","sample","strings","to","be","sorted"] : string list - ListMergeSort.sort qsort strings; val it = ["strings","sample","sorted","Here","some","are","be","to"] : string listRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.