CSC300 / CSC402: ADTs in Java [2/9] |
In Java we write this as follows (using Strings instead of plates):
01 |
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 |
StackOfStrings stack = new StackOfStrings(); stack.push("a"); if (! stack.isEmpty()) { String item = stack.pop(); } |
Note that I've told you what the operations are, and how they should behave.
I've told you nothing about how the operations are implemented.
When we look at a specific implementation, this is what we call a data structure.