/** * CharNode.java * This Class implements a stack of characters * * @author Mr J * @version 20050211 */ public class CharacterStack { CharNode item; CharNode top; /** * CharacterStack constructor. */ public CharacterStack() { top = null; } /** * Test for empty stack */ public boolean isEmpty() { return (top == null); } /** * pop character from stack - check for underflow */ public char pop() { CharNode temp; if (!isEmpty()) { temp = top; top = temp.getNext(); return temp.getItem(); } else { return '\0'; // return null char on error } } /** * push character on stack. */ public void push(char ch) { CharNode temp = new CharNode( ch, top); top = temp; } }