| 27 | |
| 28 | // Different Stack operation |
| 29 | public class CustomStack { |
| 30 | |
| 31 | int length = 0; |
| 32 | Node top = null; |
| 33 | |
| 34 | public CustomStack(){ |
| 35 | } |
| 36 | |
| 37 | public int size(){ |
| 38 | return length; |
| 39 | } |
| 40 | |
| 41 | public boolean isEmpty(){ |
| 42 | return length == 0; |
| 43 | } |
| 44 | |
| 45 | public void push(int data) { |
| 46 | Node tempNode = new Node(data); |
| 47 | tempNode.setNextNode(top); |
| 48 | top = tempNode; |
| 49 | length++; |
| 50 | } |
| 51 | |
| 52 | public int pop() { |
| 53 | if(isEmpty()){ |
| 54 | throw new EmptyStackException(); |
| 55 | } |
| 56 | Node node = top; |
| 57 | top = top.getNextNode(); |
| 58 | length--; |
| 59 | return node.getData(); |
| 60 | } |
| 61 | |
| 62 | public int peek(){ |
| 63 | if(isEmpty()){ |
| 64 | throw new EmptyStackException(); |
| 65 | } |
| 66 | return top.getData(); |
| 67 | } |
| 68 | } |
nothing calls this directly
no outgoing calls
no test coverage detected