// Show the stack's values. private void ShowStack() { itemsListBox.Items.Clear(); for (StackCell <string> cell = TheStack.Top; cell != null; cell = cell.Next) { itemsListBox.Items.Add(cell.Value); } }
// Push an item onto the stack. public void Push(T value) { StackCell <T> newCell = new StackCell <T>(); newCell.Value = value; newCell.Next = Top; Top = newCell; }
// Pop a value off of the top of the stack. public T Pop() { if (Top == null) { throw new Exception("The stack is empty."); } T result = Top.Value; Top = Top.Next; return(result); }