import java.util.Iterator; // Custom Linked List class using Generics class List implements Iterable { Node head, tail; // add new Element at tail of the linked list in O(1) public void add(T data) { Node node = new Node<>(data, null); if (head == null) tail = head = node; else { tail.setNext(node); tail = node; } } // return Head public Node getHead() { return head; } // return Tail public Node getTail() { return tail; } // return Iterator instance public Iterator iterator() { return new ListIterator(this); } }