Question: Please help with this JAVA program Complete the implementation of ArrayUnorderedList. Speci cally, implement these methods: ad- dToFront and addToRear. Don't neglect support for the
Please help with this JAVA program
Complete the implementation of ArrayUnorderedList. Speci cally, implement these methods: ad- dToFront and addToRear. Don't neglect support for the iterator in ArrayList. Do not import any packages other than those already imported.
/**
* ArrayUnorderedList represents an array implementation of an unordered list.
*
* @author Lewis and Chase
* @version 4.0
*/
public class ArrayUnorderedList
implements UnorderedListADT
{
/**
* Creates an empty list using the default capacity.
*/
public ArrayUnorderedList()
{
super();
}
/**
* Creates an empty list using the specified capacity.
*
* @param initialCapacity the intial size of the list
*/
public ArrayUnorderedList(int initialCapacity)
{
super(initialCapacity);
}
/**
* Adds the specified element to the front of this list.
*
* @param element the element to be added to the front of the list
*/
@Override
public void addToFront(T element)
{
// TODO: Implement this.
}
/**
* Adds the specified element to the rear of this list.
*
* @param element the element to be added to the list
*/
@Override
public void addToRear(T element)
{
// TODO: Implement this.
}
/**
* Adds the specified element after the specified target element.
* Throws an ElementNotFoundException if the target is not found.
*
* @param element the element to be added after the target element
* @param target the target that the element is to be added after
*/
@Override
public void addAfter(T element, T target)
{
if (size() == list.length)
expandCapacity();
int scan = 0;
// find the insertion point
while (scan < rear && !target.equals(list[scan]))
scan++;
if (scan == rear)
throw new ElementNotFoundException("UnorderedList");
scan++;
// shift elements up one
for (int shift=rear; shift > scan; shift--)
list[shift] = list[shift-1];
// insert element
list[scan] = element;
rear++;
modCount++;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
