algorithm - 阐明递归排序算法

标签 algorithm sorting

我有这个Haskell问题作为作业,细节有点复杂。我只想澄清我在这个问题上想做什么:

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.

这是否意味着“列表的第一个元素是最小的,而列表的最后一个元素是 int 只比最小的元素大且比其他元素小”?

例如,如果我有这个列表:

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

,答案应该是

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

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

?

最佳答案

你想要的是:给定一个列表 [5 3 9 8 1],你想要以下内容:

  • 一个列表,其中头部是最小的 (1),尾部是列表其余部分排序的结果 ([5 3 9 8])。
  • 原列表的尾部以头部为最小(3),尾部为[5 9 8]排序的结果
  • 等等。

关于algorithm - 阐明递归排序算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5506705/

相关文章:

algorithm - 均匀划分连续的数字序列

sorting - Elasticsearch查询返回奇怪的排序(基于分数)结果

PHP AJAX 排序数组无需重新加载页面

unix - ps按开始时间排序结果

javascript - 如何按日期对 Javascript 对象数组进行排序?

algorithm - 括号组合的时间复杂度

algorithm - 解析类继承算法

java - 插入排序、合并排序和快速排序的测试用例

java - 对 lambda 表达式的随机搜索

algorithm - 图上距离动态变化的最短路径? (最大能量路径)