在排序列表中递归地插入,删除检索

时间:2012-02-08 06:11:25

标签: java data-structures recursion linked-list

嗨大家我不太明白以下教程问题: 编写ADT排序列表,必须以递归方式实现插入,删除和检索操作。 [注意:递归要求可以通过实现在插入/删除或检索方法中使用的递归搜索函数来实现。

你如何实现一个做3件事的方法? 我知道教授要求实现搜索方法,但插入删除检索需要不同的操作。

感谢

1 个答案:

答案 0 :(得分:4)

您的教授说您可以使用搜索方法作为实现插入或删除方式的一部分。抽象地说,您有三个任务:

search(x):  find where x should appear in the sorted list, then return it
insert(x):  find where x should appear in the sorted list, then put it there
delete(x):  find where x should appear in the sorted list, then remove it

使用您的搜索实现可以实现插入和删除方法的find where x should appear in the sorted list部分。

你教授不期望你写一个方法来做所有这三件事,而是给你一个提示,你的搜索方法可以在你的插入和删除方法中使用。

相关问题