CSC300: ADTs in Java [3/9] Previous pageContentsNext page

In Java we write this as follows (using Strings instead of plates):

01
02
03
04
05
06
07
package algs13;
public class StackOfStrings {
  public StackOfStrings          { /* ... */ }
  public boolean isEmpty ()      { /* ... */ }
  public void push (String item) { /* ... */ }
  public String pop ()           { /* ... */ }
}

We use the ADT as follows:

08
09
10
  StackOfStrings stack = new StackOfStrings();
  stack.push("a"); 
  if (! stack.isEmpty()) { String item = stack.pop(); }

Previous pageContentsNext page