Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Linked List Add Node To Head
public class LinkedList<T> {
// Reference to the head node
Node head;
public void addToHead(T data){
// create the new Node and add head as its next
Node newNode = new Node(data, head);
// replace head with the new node
head = newNode;
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment