插入排序 - 链接列表 - 递归

时间:2014-09-04 04:22:09

标签: algorithm sorting

我一直在尝试编写一个程序来使用插入排序对链表进行排序,我发现的解决方案是迭代地执行此操作,我们如何编写递归算法?

PS。这不是一个任务问题。

1 个答案:

答案 0 :(得分:0)

To insert a node n to a list L:
   If L is empty, return n
   Split L into L0 (the head, first item in L) and LR (the rest)
   If n.data < L0.data then insert n at the head of L and return L
   insert n into LR and return L
相关问题