// reverse.java // stack used to reverse a string // to run this program: C>java ReverseApp import java.io.*; // for I/O //////////////////////////////////////////////////////////////// class StackX { private int maxSize; private char[] stackArray; private int top; //-------------------------------------------------------------- public StackX(int max) // constructor { maxSize = max; stackArray = new char[maxSize]; top = -1; } //-------------------------------------------------------------- public void push(char j) // put item on top of stack { stackArray[++top] = j; } //-------------------------------------------------------------- public char pop() // take item from top of stack { return stackArray[top--]; } //-------------------------------------------------------------- public char peek() // peek at top of stack { return stackArray[top]; } //-------------------------------------------------------------- public boolean isEmpty() // true if stack is empty { return (top == -1); } //-------------------------------------------------------------- } // end class StackX //////////////////////////////////////////////////////////////// class Reverser { private String input; // input string private String output; // output string //-------------------------------------------------------------- public Reverser(String in) // constructor { input = in; } //-------------------------------------------------------------- public String doRev() // reverse the string { int stackSize = input.length(); // get max stack size StackX theStack = new StackX(stackSize); // make stack for(int j=0; j