Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RakhmedovRS/f18182ba692a76502f4444bf58410af6 to your computer and use it in GitHub Desktop.
Save RakhmedovRS/f18182ba692a76502f4444bf58410af6 to your computer and use it in GitHub Desktop.
/**
* Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.
*/
public void addAtHead(int val)
{
Link link = new Link(val);
//-->
head.next.prev = link;
link.next = head.next;
//<--
head.next = link;
link.prev = head;
size++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment