Linked List Operation


Suppose we have the following linked list and we want to add a new node to the front of it.

Exercise Complete the implementation of the addFirst method that creates a node and adds it to the front of the list.

public void addFirst (T data) {
  // TODO Implement Me!

Hint: Use the following visualization as a guidance:

public void addFirst(T t) {
  Node<T> node = new Node<>(t);
  // = null; // no need: done by default! = head;
  head = node;