Question: Assume the KWLinkedList class which is similar to java build - in class is given to you ( as discussed in the class, and the

Assume the KWLinkedList class which is similar to java build-in class is given to you (as discussed in the class, and the complete class is uploaded on the blackboard), do the following with the help of ListIterator or without ListIterator. It is also up to you in required member methods below to call any other method within the class or not.
(A) Write a method called removeAll within the class that has one parameter item of type E that removes all the elements equal to item in the list. The method head is
public void removeAll(E item)
(B) Write a method called addOnce within the class that has one parameter item of type E, which adds item to the end of the list if item does not exist in the list. The method head is
public void addOnce(E item)
(C) Write a method called removeSecond within the class that has one parameter item of type E that removes the second element in the list equals to item if exists. The method head is
public void removeSecond(E item)
(D) Write a method called compareListsHalfs within the KWLinkedList class that has one parameter list of type KWLinkedList. The method returns true if all the elements in the first half of list (starting from the head) are greater than all the elements in the second half of the this list, otherwise, it returns false. You need to ensure first that the two lists (list and this) are having the same size and have even number of elements. The method head is
public boolean compareListsHalfs(KWLinkedList list)
Example1:
head
list: 72886310044158955
this:
head
6035544370110533
The return value is false
Example2:
head
list: 70886310044158955
this:
head
603575436255533
The return value is true
(E) Write a class called App that contains the main method, the main method contains some operations performed on some constructed lists (you may create two objects l1 and l2 from the class KWLinkedList), and among these operations are the four stated above. Show the output of the above-mentioned methods when they are performed.

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!