Raju Kumar
Raju Kumar

Reputation: 1265

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

Upvotes: 2

Views: 455

Answers (1)

Timothy Jones
Timothy Jones

Reputation: 22135

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.

Upvotes: 4

Related Questions