The code below was sketched on-line. For working code, see StackFromVector.java.
// growable array
Class Vector          in java.util
{
C elementAt(int i)    //returns V[i]
void addElement(C X)  //adds new position at end of array, puts X in it
}

Class Stack extends Vector
{
void push(C X)
  { addElement(X); }
C pop()
  {
  C temp = elementAt(length()-1);
  resize(length()-1);
  return temp;
  }

 

To Next Slide To Previous Slide To Contents