Source of 5.4.java


  1: // @author Frank M. Carrano
  2: // @author Timothy M. Henry
  3: // @version 5.0
  4: StackInterface<String> stringStack = new OurStack<>();
  5: stringStack.push("Jim");
  6: stringStack.push("Jess");
  7: stringStack.push("Jill");
  8: stringStack.push("Jane");
  9: stringStack.push("Joe");

 11: String top = stringStack.peek(); // Returns "Joe"
 12: System.out.println(top + " is at the top of the stack.");

 14: top = stringStack.pop();         // Removes and returns "Joe"
 15: System.out.println(top + " is removed from the stack.");

 17: top = stringStack.peek();        // Returns "Jane"
 18: System.out.println(top + " is at the top of the stack.");

 20: top = stringStack.pop();         // Removes and returns "Jane"
 21: System.out.println(top + " is removed from the stack.");