JSFiddle - React, Tailwind, and code Playground
by farhan2056
JavaScript
function Node(element,next=null){
this.val = element;
this.next = next;
}
function LinkedList(){
this.head = null;
}
LinkedList.prototype.insert = function(element){
let node = new Node(element)
node.next = this.head;
this.head = node;
return this.head;
}
var l1 = new LinkedList();
l1.insert(2)
l1.insert(3)
console.log(l1.head.val, l1.head.next.val,l1.head.next.next)