简体   繁体   中英

insertion, deletion retrieval recursively in sorted list

Hi Guys I don't quite understand the following tutorial question: write a ADT sorted list, The insertion, deletion and retrieval operations must be implemented recursively. [Note: The recursive requirement could be achieved by implementing a recursive search function that is used within the insertion/deletion or retrieval methods.

How can you implement one method that does 3 things? I know that the professor is asking to implement a search method, but inserting deleting retrieving requires different operations.

thanks

Your professor is saying that you can use the search method as part of the way you achieve insert or delete. Abstractly, you have three tasks:

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

The find where x should appear in the sorted list part of both the insert and delete methods could be achieved using your implementation of search.

You professor isn't expecting you to write one method that does all three things, but instead is giving you the hint that your search method can be used inside your insert and delete methods.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM