Last active
August 10, 2018 17:21
-
-
Save thedineshj/faa957ef5ffdf2d72f68e8d4104b5e8d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addToHead(data) { | |
let newNode = new node(data); | |
/* | |
If the list is empty , | |
newly created `node` | |
will be the `head` of the list. | |
*/ | |
if (this.head == null) { | |
this.head = newNode; | |
} | |
/* | |
If not, | |
we will point `next` | |
of the newly created `node` | |
to the current `head` of the list | |
and then set `head` of the list to newly created node | |
*/ | |
else { | |
newNode.next = this.head; | |
this.head = newNode; | |
} | |
/* | |
increment length | |
*/ | |
this.length++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment