Repeat Exercise, but define the method remove(n), as described in the previous exercise, instead of the method display.
Suppose that the ADT stack included the void method display, which displays the entries in a stack. Implement this method for each of the following classes:
a. LinkedStack, as outlined in Listing.
b. ArrayStack, as outlined in Listing.
c. VectorStack, as outlined in Listing.
d. Any client of LinkedStack, ArrayStack, or VectorStack.
LISTING An outline of a linked implementation of the ADT stack
/**A class of stacks whose entries are stored in a chain of nodes.@author Frank M. Carrano*/public class LinkedStackimplements StackInterface { private Node topNode; // references the first node in the chain public LinkedStack() { topNode = null; } // end default constructor . . . private class Node { private T data; // entry in stack private Node next; // link to next node } // end Node} // end LinkedStack
LISTING An outline of an array-based implementation of the ADT stack
/**A class of stacks whose entries are stored in an array.@author Frank M. Carrano*/public class ArrayStackimplements StackInterface { private T[] stack; // array of stack entries private int topIndex; // index of top entry private static final int DEFAULT_INITIAL_CAPACITY = 50; public ArrayStack() { this(DEFAULT_INITIAL_CAPACITY); } // end default constructor public ArrayStack(int initialCapacity) { // the cast is safe because the new array contains null entries @SuppressWarnings("unchecked") T[] tempStack = (T[])new Object[initialCapacity]; stack = tempStack; topIndex = -1; } // end constructor . . .} // end ArrayStack
LISTING An outline of a vector-based implementation of the ADT stack
import java.util.Vector;/**A class of stacks whose entries are stored in a vector.@author Frank M. Carrano*/public class VectorStackimplements StackInterface { private Vector stack; // last element is the top entry in stack private static final int DEFAULT_INITIAL_CAPACITY = 50; public VectorStack() { this(DEFAULT_INITIAL_CAPACITY); } // end default constructor public VectorStack(int initialCapacity) { stack = new Vector (initialCapacity);// size doubles as needed } // end constructor . . .} // end VectorStack
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.