//A stack is a structure that allows you to add and remove //elements from it, where the last in is the first out. //That is, if you add 'a', then 'b', then the next time you //remove an element, it must be 'b'. public class Stack { //Data member. LinkedList list; int count; public Stack() { list = new LinkedList(); count = 0; } //push something onto the stack. public void push(int n) { list.insert(n); count++; } //take an item off the top of the stack and remove it. public int pop() { int res = list.getVal(0); list.remove(0); count--; return res; } //return the item on the top off the stack. public int peek() { return list.getVal(0); } public int size() { //return list.length(); return count; } }