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

Write the following methods on the LinkedList class. The methods should not call

ID: 3540336 • Letter: W

Question



Write the following methods on the LinkedList class. The methods should not call any other methods in your LinkedList class(that is, for example, if you need to add a node to the linked list, don't call insert method; instead, do the insertion inside the methods you will write).


/**Adds the elements in otherlist to this list.

* Returns true if this list changed as a result of the call */

public Boolean addAll(MyList<E> otherList)


/** Removes all the elments in otherList from this list

* Returns true if this list changed as a result of the call */

public Boolean removeAll(MyList<E> otherList)


/** Retains the elements in this list that are also in otherList

* Returns true if this list changed as a result of the call */

public Boolean retainAll(myList<E> otherList)

Ok this is how I would do it if i could call other method, but I am not sure how to do it without clling for another method

public boolean addAll(MyList<E> otherList) {

            if (otherList != null) {

                     addAll(otherList);

                     return true;

               } else

                     return false;

      }


      public boolean removeAll(MyList<E> otherList) {

            if (otherList != null) {

                     removeAll(otherList);

                     return true;

            } else

                       return false;

      }


      public boolean retainAll(MyList<E> otherList) {

            if (otherList != null) {

                     retainAll(otherList);

                     return true;
                } else

                     return false;

}

Thanks

Explanation / Answer

i am just giving u hint ..if u can understand it then ok otherwise i am free to answer ur query


try this


for insertion write in main method


while(1)

{

if (otherList != null) {

//code for go down to list means change the value of otherList

continue;

  
}

else

{

// code for insertion a node

}


similarly u can write for other operation