Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Write a contains method for a linked implementation of a sorted list. This

ID: 3605763 • Letter: J

Question

Java

Write a contains method for a linked implementation of a sorted list.

This method is written from the implementation perspective, meaning it goes inside of the SortedLinkedList class.

This means you have access to firstNode and numberOfEntries.

The method header is:

public boolean contains(T anEntry)

For full credit, write an efficient solution.

This will involve directly accessing the linked structure rather than only invoking existing methods.

You should also take advantage of the knowledge that the list is always sorted.

You can assume T is Comparable.

SortedLinkedList class file : http://www.mediafire.com/file/rsiwh42rjt9s0bp/HomeworkW10Driver.zip

Explanation / Answer

Please find my implementaton of required method.

public boolean contains(T anEntry) {

Node currentNode = firstNode;

while(currentNode != null) {

if(currentNode.getData().compareTo(anEntry) == 0)

return true;

currentNode = currentNode.getNextNode();

}

return false; // not found

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote