Question: Problem 1: Add the method below that prints every other element in the stack, starting with the top element. You can assume there are an



Problem 1: Add the method below that prints every other element in the stack, starting with the top element. You can assume there are an even number of elements in the stack. For example, if the stack contains the elements 2 4 6 8 10 12, where 2 is the top, then this method will print 26 10". public void printEveryother () { Problem 2: Add the method below that adds the given element to the stack...except it is added as the second element, not the top element. For example, if the stack contains 2 4 6 8 10 12, and we want to add 7, then the stack will be 2 7 4 6 8 10 12. Throw the EmptyStackException if the stack is empty. public void addSecond (E element) { Problem 3: Add the method below that removes and returns the bottom element from the stack. For example, if the stack contains 2 4 6 8 10 12, then this method will remove the 12. Do not add a new field variable to the class. public E removeBottom () { Problem 4: Add the method below that returns an array containing the elements that are in the stack, in the same order (where the top element will be the first element in the array). The array will be an Object array and should have the same size as the stack. The method must not make any changes to the stack. For example, if the stack contains 2 4 6 8 10 12, then this method will return the array 24681012 public Object[] toArray() { public class LinkedStack
Step by Step Solution
There are 3 Steps involved in it
Lets implement the methods one by one for the LinkedStack class based on the problems described Prob... View full answer
Get step-by-step solutions from verified subject matter experts
