Skip to content

Instantly share code, notes, and snippets.

@mjarpitanand
Created November 24, 2017 06:07
Show Gist options
  • Save mjarpitanand/04b672f8136e2029e6340575cad26b4c to your computer and use it in GitHub Desktop.
Save mjarpitanand/04b672f8136e2029e6340575cad26b4c to your computer and use it in GitHub Desktop.
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