@@ -0,0 +1,1745 @@
+/*%0A *A stack is exactly what it sounds like. An element gets added to top of the stack and only the element on the top may be removed.%0A *This is an example of an array implementation of a Stack. So an element can only be added/removed from the end of the array.%0A *In theory stacks have no fixed size, but with an array implementation it does.%0A*/%0Aclass Stack%7B%0A%09private int maxSize;%0A%09private int%5B%5D stackArray;%0A%09private int top;%0A%0A%09public Stack(int size)%7B //Constructor%0A%09%09maxSize = size;%0A%09%09stackArray = new int%5BmaxSize%5D;%0A%09%09top = -1;%0A%09%7D%0A%0A%09public void push(int value)%7B //Adds an element to the top of the stack%0A%09%09top++;%0A%09%09stackArray%5Btop%5D = value;%0A%09%7D%0A%0A%09public int pop()%7B //Removes the top element of the stack and returns the value you've removed%0A%09%09return stackArray%5Btop--%5D;%0A%09%7D%0A%0A%09public int peek()%7B //Returns the element at the top of the stack%0A%09%09return stackArray%5Btop%5D;%0A%09%7D%0A%0A%09public boolean isEmpty()%7B //Returns true if the stack is empty%0A%09%09return(top == -1);%0A%09%7D%0A%0A%09public boolean isFull()%7B //Returns true if the stack is full%0A%09%09return(top+1 == maxSize);%0A%09%7D%0A%09public void makeEmpty()%7B //Doesn't delete elements in the array but if you call%0A%09%09top = -1;%09%09%09 //push method after calling makeEmpty it will overwrite previous values%0A%09%7D%0A%7D%0A//Example%0Apublic class Stacks%7B%0A%09public static void main(String args%5B%5D)%7B%0A%09%09Stack myStack = new Stack(4); //Declare a stack of maximum size 4%0A%09%09//Populate the stack%0A%09%09myStack.push(5);%0A%09%09myStack.push(8);%0A%09%09myStack.push(2);%0A%09%09myStack.push(9);%0A%0A%09%09System.out.println(myStack.isEmpty()); //will print false%0A%09%09System.out.println(myStack.isFull()); //will print true%0A%09%09System.out.println(myStack.peek()); //will print 9%0A%09%09System.out.println(myStack.pop()); //will print 9%0A%09%09System.out.println(myStack.peek()); // will print 2%0A%09%7D%0A%7D%0A

Create Stacks.java