2012-02-08 65 views
2

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

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

感谢

+0

这功课吗? – DarthVader 2012-02-08 06:12:57

+0

不,其额外的工作,它取决于我,如果我想这样做。 – 2012-02-08 06:13:47

回答

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部分和删除可以用搜索的执行来实现的方法。

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

+0

就是这样!谢谢我理解得更好。 – 2012-02-08 06:21:42