This class uses an inner class called ‘Node’, implements the Iterable interface,
ID: 668920 • Letter: T
Question
This class uses an inner class called ‘Node’, implements the Iterable interface, and has another inner class called NodeIterator that implements the Iterator interface.
Class SimpleLinkedList
A simple linked list implementation that uses an inner Node class.
Constructors
public SimpleLinkedList()
// Create an empty list.
public SimpleLinkedList(T[] items)
// Create a list containing the given items.
Methods
public T get(int index)
// Obtain the item at the given index.
public void set(int index, T item)
// Replace the item at the given index with the given item.
public void add(T item)
// Add the given item to the end of the list.
public void addAll(T[] items)
// Add the given items to the end of the list.
public void insert(int index, T item)
// Inserts the given item at the given index.
public void remove(T item)
// Removes the first occurrence of the given item from the list.
public void removeAt(int index)
// Removes the item at the given index.
public Iterator<T> iterator()
// Obtains an iterator for traversing the list.
public int indexOf(T item)
// Returns the index of the first occurrence of the given item in the list.
// Returns -1 if item not in the list.
public int size()
// Obtains the size of the list.
public void trimToSize(int size)
// Discard all elements beyond index (size-1).
A JUnit tests for SimpleLinkedListmust be written, putting them in a class called SimpleLinkedListTest (stored in the file SimpleLinkedListTest.java). The following 4 tests must be included:
check that a linked list created using the constructor (with a list of items passed in as a parameter) contains the items passed in.
check that indexOf applied to search through a linked list of items returns the correct index for each item in the list.
check that the insertion of an item in a linked list of items using insert (...) results in the item being inserted and appearing in the correct position.
check that trimToSize (...) does truncate the list to the size specified.
Explanation / Answer
//header files
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.