class GenericStackLinkedList<T> { private Node<T> top; public GenericStackLinkedList() { this.top = null; } public void push(T item) { Node<T> newNode = new Node<>(item); newNode.next = top; top = newNode; } public T pop() { if (top == null) { System.out.println("Stack Underflow"); return null; } T data = top.data; top = top.next; return data; } public boolean isEmpty() { return top == null; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter