Question: Set the initial capacity to 10 when initially constructed Make sure your dynamic array class implements the generics as specified by the interface (Java warnings/errors
- Set the initial capacity to 10 when initially constructed
- Make sure your dynamic array class implements the generics as specified by the interface (Java warnings/errors will help with this).
- Do not use Java library structures (except for the method "toJavaList")
- The "DynamicList" interface is read-only. It must not be changed (it's common/standard for all)
- You may ignore the "Optional" section in the DynamicList interface (end of file)
package Linearpub; import java.util.Iterator; import java.util.List; import java.util.function.Function; public interface DynamicListextends Iterable { //-------------------- Basic Statistics --------------------- int size(); boolean isEmpty(); //--------------------- Accessing --------------------- E get(int index); /** * Return a new list containing the elements of this list * between the given index "start" (inclusive) and * the given index "stop" (exclusive). * Throws IndexOutOfBoundsException if either passed index is invalid. */ DynamicList subList(int start, int stop); /** * Return first element * Throws RuntimeException if list is empty */ E first(); /** * Return last element * Throws RuntimeException if list is empty */ E last(); /** * Return index of first matching element (where searchFct outputs true) * Return -1 if no match */ int find(Function searchFct); //--------------------- Adding --------------------- /** * Add the passed element to start of list */ void addFirst(E newElem); /** * Add the passed element to end of list */ void addLast(E newElem); /** * Alias for "addLast" (same functionality). */ void add(E newElem); /** * Insert passed element into list at the passed index * Throws IndexOutOfBoundsException if passed index is invalid. */ void insert(int index, E newElem); //--------------------- Removing --------------------- /** * Remove first element * Return removed element * Throws RuntimeException if list is empty */ E removeFirst(); /** * Remove last element * Return removed element * Throws RuntimeException if list is empty */ E removeLast(); /** * Reset the list so it is empty. * If list is already empty, then do nothing * No action is performed on the elements. * */ void removeAll(); /** * Remove elem at index * Return the removed element * Throws IndexOutOfBoundsException if passed index is invalid. */ public E removeIndex(int index); /** * Remove first matching element (where searchFct outputs true) * Return the removed element * If no match, return null */ E remove(Function searchFct); //--------------------- Convenience --------------------- /** * Return a Java "List " containing all elements in this list. */ List toJavaList(); /** * Returns one-line user-friendly message about this object * Helpful method especially for debugging. */ String toString(); //--------------------------------------------------------------------- //--------------------- Optional --------------------- /** * Return iterator on this list */ default Iterator iterator() { throw notImplemented(); } private static RuntimeException notImplemented() { return new RuntimeException("Not Implemented"); } }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
