Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clarifying a recursive sorting algorithm

I have this Haskell question as homework, and the details are a little complicated. I'd just like to clarify what I am trying to do in this question:

Define the function select which takes a list of integers and returns the list whose head is the smallest element in the list and whose tail is the result of recursively sorting the list obtained by deleting the smallest element of the list from the list.

Does this mean something like "the first element of the list is the smallest, and the last element of the list is the int just bigger than the smallest and smaller than everything else"?

For example if I have this List:

[ 2, 3, 4, 6, 8, 7]

,should the answer be

[2, 4, 6, 8, 7, 3]

or

[2, 4, 6, 7, 8, 3]

?

like image 584
steven Avatar asked Apr 22 '26 17:04

steven


1 Answers

What you want is: Given a list [5 3 9 8 1], you want the following:

  • A list where the head is the smallest (1), and the tail is the result of sorting the rest of the list ([5 3 9 8]).
  • The tail of the original list has the head as the smallest (3), and the tail is the result of sorting [5 9 8]
  • And so on.
like image 115
Kevin Lacquement Avatar answered Apr 24 '26 09:04

Kevin Lacquement



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!