print
method in
StackTester.java (and
QueueTester.java), it is probably better
to add a toString
method to the implementation
ArrayStack.java and replace
print(stack)
in the
StackTester.java
with System.out.print(stack)
. The former does destroy the stack
whereas the latter doesn't.
/** * Returns a string representation of this stack. * @return A string representation of this stack. */ public String toString() { String rep = ""; for (int i = 0; i <= top; i++) { rep += stack[i].toString(); rep += "\n"; } return rep; }Stack.java
The implements Stack
in
ArrayStack.java
specifies that the class ArrayStack
implements all the methods
of the interface Stack
.