| 11 | } |
| 12 | |
| 13 | static class Stack { |
| 14 | public static Node head = null; |
| 15 | public static void push(int data) { |
| 16 | Node newNode = new Node(data); |
| 17 | |
| 18 | if(head == null) { |
| 19 | head = newNode; |
| 20 | return; |
| 21 | } |
| 22 | newNode.next = head; |
| 23 | head = newNode; |
| 24 | } |
| 25 | |
| 26 | public static boolean isEmpty() { |
| 27 | return head == null; |
| 28 | } |
| 29 | |
| 30 | public static int pop() { |
| 31 | if(isEmpty()) { |
| 32 | return -1; |
| 33 | } |
| 34 | Node top = head; |
| 35 | head = head.next; |
| 36 | return top.data; |
| 37 | } |
| 38 | |
| 39 | public static int peek() { |
| 40 | if(isEmpty()) { |
| 41 | return -1; |
| 42 | } |
| 43 | Node top = head; |
| 44 | return top.data; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | public static void main(String args[]) { |
| 49 | Stack stack = new Stack(); |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…