Question: Assume the following method is in class TestSLList ( a method outside the SingleLinked List class ) . public static void Method 3 ( SingleLinkedList

Assume the following method is in classTestSLList(a method outside theSingleLinked Listclass).
public static void Method3( SingleLinkedListlist, Eitem1, Eitem2)
{
if( list.contains(item1) && list.contains(item2))
{
int index2= list.indexOf (item2);
list.remove(index2);
list.add( list.size(), item2);
}
}
What is the purpose of the above method:
If bothitem1anditem2exist in thelistthen the method will deleteitem1from thelist.
If bothitem1anditem2exist in thelistthen the method will deleteitem2from thelist and add item 2 to the end of the list.
If bothitem1anditem2exist in thelistthen the method will swapitem1anditem2in thelist.
If bothitem1anditem2exist in thelistthen the method will delete bothitem1 anditem2from thelist.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!