Question: Write a class named CustomList.java that is a subclass of CMSC 2 5 6 LinkedList.java. The CustomList class must contain the following methods: / *

Write a class named CustomList.java that is a subclass of CMSC256LinkedList.java. The CustomList class must contain the following methods:
/**
* Returns the middle element of the
* If the number of elements in the list is even, there will be two middle nodes,
* so return the second one.
* For example, if the list contains [23,34,98,22,12,76,81], the
* method returns 22
* If the list contains [23,34,98,22,12,76,81,101], the
* method returns 12
* @throws IllegalStateException if the list is empty or null
* @return an instance T
*/
public T getMiddleElement()
/**
* Returns the first half of the list.
* If the number of elements in the list is odd, include the extra element.
* For example if the list contains [23,34,98,22,12,76,81], the
* method returns a list [23,34,98,22]
*
* @return an instance of a class that implements the ListInterface
**/
public ListInterface getFirstHalf()
/**
* Returns the last half of the list.
* If the number of elements in the list is odd, exclude the extra element.
* For example if the list contains [23,34,98,22,12,76,81], the
* method returns a list containing [12,76,81]
*
* @return an instance of a class that implements the ListInterface
**/
public ListInterface getLastHalf(){
/**
* Returns a List that consists of all and only the elements
* in every fourth positions (i.e., fourth, eighth, and so on) in
* the current string, in the same order as the current list.
* If the list contains [23,34,98,22,12,76,81,101], the
* method returns [22,101]
* @return an instance of a class that implements the ListInterface
*/
public ListInterface getEveryFourthElement()
/**
* @return true if there are any elements in the list that occur twice
* false otherwise
* Note: if an element occurs more that twice, do not include it
* If the list contains [23,34,98,22,12,76,81,101,12,23,33,23], the
* method returns true
*/
public boolean hasDuplicates()
/**
* @return an instance of a class that implements the ListInterface that
* contains those elements in this list that appear more than once.
* If the list contains [23,34,98,22,12,76,81,101,12,23,33,23], the
* method returns [23,12]
**/
public ListInterface getAllMultiples(){
/**
* Alters the list by deleting any elements that occur twice in the list.
* Elements that occur more than 2 times remain in the list.
* If the list contains [23,34,98,22,12,76,81,101,12,23,33,23], the
* method removes 12 and the list becomes [23,34,98,22,76,81,101,23,33,23]
*/
public void removeAllDuplicates()
/*
* Removes the nth node from the end of the list
* For example, if the list contains [43,68,11,5,69,37,70] and 1 is passed to the method
* a value of 70 is returned and the list becomes [43,68,11,5,69,37]
* @return the element from the position that was removed
**/
public T removeNthNodeFromEnd(int n)

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!