| 1 | class stackArray { |
| 2 | public static void main(String[] args) { |
| 3 | StackX theStack = new StackX(10); // create a stack with max size 10 |
| 4 | |
| 5 | theStack.push(30); // insert given items |
| 6 | theStack.push(80); |
| 7 | theStack.push(100); |
| 8 | theStack.push(25); |
| 9 | |
| 10 | //To peak the the last element pushed |
| 11 | System.out.println(theStack.peek()); |
| 12 | |
| 13 | while(!theStack.isEmpty()) { // until it is empty, delete item from stack |
| 14 | |
| 15 | double val = theStack.pop(); |
| 16 | System.out.print(val); |
| 17 | System.out.print(" "); |
| 18 | } |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | //Implementation of Stack Class |