public void push(int data) { Console.Write("inserted value " + data + "\n"); StackClassNode node = new StackClassNode(data); node.next = top; top = node; count++; }
public void printStack() { StackClassNode runner = top; while (runner != null) { Console.Write("| " + runner.data + " |\n"); runner = runner.next; } Console.Write("\n"); }
public int pop() { StackClassNode runner = top; int val; count--; val = runner.data; top = runner.next; Console.Write("popped value " + val + "\n"); return(val); }
public bool contain(int data) { StackClassNode runner = top; while (runner != null) { if (data == runner.data) { return(true); } runner = runner.next; } return(false); }
public StackClassNode reveserAll() { StackClassNode runner = top, prev = null; if (runner == null) { return(runner); } while (runner != null) { StackClassNode next = runner.next; runner.next = prev; prev = runner; runner = next; } top = prev; return(top); }
public StackClassNode(int value) { data = value; next = null; }
public Stack() { top = null; this.count = 0; }