public class MyStackImpl implements MyStack { private Node head; private int size; public MyStackImpl() { head = null; size = 0; } public boolean isEmpty() { return size == 0; } public int pop() { if (size == 0) { throw new RuntimeException("No element left"); } int result = head.value; head = head.next; size--; return result; } public void push(int val) { if (isEmpty()){ head = new Node (val); } else { Node node = new Node (val); node.next = head; head = node; } size++; } }