Problem

Repeat Exercise, but define the method remove(n), as described in the previous exercise, i...

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 LinkedStack implements 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 ArrayStack implements 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 VectorStack implements 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

Step-by-Step Solution

Request Professional Solution

Request Solution!

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.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 6
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT