
public class Stack<E> extends LinkedList<E> {
	
	public void push(E newElem) {
		add(0, newElem);
	}

	public E pop() {
		return remove(0);
	}

	public E peek() {
		return get(0);
	}

	/*
	 * this is not a part of the class---we added this method for a test in class
	@Override
    protected Node<E> getNode(int index) {
		System.out.println("In stack!");
        Node<E> current = head;
        for (int skips = 0; skips < index; skips++) {
            // current is now the skips-th node in the list
            current = current.getNext();
        }
        return current;
    }*/

	public static void main(String[] args) {
		//"Diamong operator" allows us to skip second Integer
		Stack<Integer> st = new Stack<>();

		st.push(1);
		st.push(2);
		System.out.println(st.peek());
		System.out.println(st.pop());
		System.out.println(st.pop());
	}
}
