Question: Implement the push(), pop(), and peek() methods for efficient execution using an ArrayListbacking store. Since you can use the ArrayList to do much of the
Implement the push(), pop(), and peek() methods for efficient execution using an ArrayListbacking store. Since you can use the ArrayList to do much of the work, you must also write a class of JUnit test methods provide 100% coverage of your methods.
import java.util.ArrayList; import java.util.EmptyStackException;
/** * Class which wraps Java's built-in {@link ArrayList} implementation so that it adds & removes elements from the end of * the List to improve efficiency AND uses the traditional method names. * * @param
/** Create a new (empty) instance of this class. */ public ProperStack() { store = new ArrayList<>(); }
/** * Adds an item to the end of the stack. Traditionally, this is the only method available to add data to a Stack. * * @param item Element to be added to the end of the stack. * @return Element added to the Stack (e.g., {@code item}). */ public E push(E item) {
}
/** * Removes and returns the element at the top of this Stack. Traditionally, this is the only method available to * remove data from the Stack. * * @return Element that was removed from the top of the Stack. * @throws EmptyStackException Thrown when the Stack does not have any elements to remove. */ public E pop() {
}
/** * Like {@link #pop()}, this returns the element at the top of the Stack, but unlike {@link #pop} this method DOES NOT * remove the element. * * @return Element that is at the top of the Stack. */ public E peek() {
} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
