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

Hi everyone this is the last question in my homework and I don\'t understant how

ID: 3564153 • Letter: H

Question

Hi everyone

this is the last question in my homework and I don't understant how to wirte it, and I cannot found any example from the text book. so, please help~~!!

As specified in this chapter, the sorted list can contain duplicate entries. Specify a sorted list of unique items. For example, add could return true if it added an entry to the list but return false if the entry is in the list already.Write a complete method with this header: public boolean add(T newEntry). This method would go inside a class that implements the SortedListInterface and replace the existing add method. This method differs from the current add method in that it will not allow the user to add duplicate items. Note: you can invoke any methods from the SortedListInterface class. Also, it's possible you would want to keep the existing implementation of add as a private method in your class to help with the current implementation. If you want to do this, you can just invoke addPrivate in your solution.

Explanation / Answer

T []arr = new T[size]; // Array having the enteries of the list

public boolean add(T newEntry)

{   

   for(int i =0 ; i<size ; i++)

{

   if(T[i]==newEntry)

return false ;

   else

{   

T[++size]= newEntry;

   return true ;

}   

     

}

}

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