Question
Code: import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.NoSuchElementException; public class UArrayList extends AArrayList implements UnorderedListADT { // Append element to list (at the end) // allocate
Code:
import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.NoSuchElementException;
public class UArrayList
// Append element to list (at the end) // allocate larger array when list is full @Override public boolean add(T element) { if (isFull()) // list is full growList();
listArray[listSize++] = element; modifiedCount++; return true; }
// Add element to front of the list // allocate larger array when list is full @Override public void addToFront(T element) { // TODO Auto-generated method stub
}
// Add element after an existing element in the list // Throw NoSuchElementException if existingElement is not found in the list @Override public void addAfter(T existingElement, T element) throws NoSuchElementException {
}
// Add element at specified index location // Throw IndexOutOfBoundsException if index is invalid public void addAt(int index, T element) throws IndexOutOfBoundsException { // TODO Auto-generated method stub
}
}
ListADT Code:
import java.util.NoSuchElementException;
public interface ListADT
// Append "it" at the end of the list for unordered lists // Add at appropriate position for ordered lists // The list must ensure that the list's capacity is not exceeded public boolean add(T it);
// Remove and return the current element public T remove(T element) throws NoSuchElementException;
// Remove and return the first element public T removeFirst() throws NoSuchElementException;
// Remove and return the last element public T removeLast() throws NoSuchElementException;
// Return the number of elements in the list public int size();
// Tell if the list is empty or not public boolean isEmpty();
// Return the first element in the list public T first();
// Return the last element in the list public T last();
// Tell if the element exists in the list public boolean contains(T element);
// Return the index of the specified element public int indexOf(T element);
// Copies the elements of the list onto the parameter array public void toArray(T[] anArray);
/* * Unused methods below * * // Insert "it" at the current location // The list must ensure that the * list's capacity is not exceeded public boolean addAtCurrent(T it); * * // Remove and return the current element public T removeCurrent() throws * NoSuchElementException; * * // Return the position of the current element public int currPos(); * * // Set the current position to "pos" public boolean moveToPos(int pos); * * // Return true if current position is at end of the list public boolean * isAtEnd(); * * // Return the current element public T getCurrentValue() throws * NoSuchElementException; * * // Set the current position to the start of the list public void * moveToStart(); * * // Set the current position to the end of the list public void moveToEnd(); * * // Move the current position one step left, no change if already at * beginning public void prev(); * * // Move the current position one step right, no change if already at end * public void next(); * * End of unused methods */
}
1. 2. + addToFront(T element) - add element at the front of the list, existing elements should shift + addAfter(T existingElement, T element) - add new element after an existing element, all elements after the element should be shifted
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started