Created
November 24, 2017 06:07
-
-
Save mjarpitanand/04b672f8136e2029e6340575cad26b4c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function LinkedList(){ | |
let head = null; | |
let node = function(ele){ | |
this.ele = ele; | |
this.next = null; | |
} | |
this.insertFirst = function(ele){ | |
let n = new node(ele); | |
if(head === null){ | |
head = n; | |
}else{ | |
let cur = head; | |
while(cur.next){ | |
cur = cur.next; | |
} | |
cur.next = n; | |
} | |
} | |
this.print = function(){ | |
while(cur.next){ | |
console.log(cur.ele); | |
} | |
} | |
} | |
let l = new LinkedList(); | |
l.insertFirst(1); | |
l.print(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment