JSFiddle - React, Tailwind, and code Playground

by Shridhar Baddur

JavaScript

/* 10 --> 5 --> 16 */
class Node {
	constructor(value) {
  	this.value = value;
    this.next = null;
  }
}

class LinkedList {
	
	constructor() {
  	this.head = null;
    this.length = 0;
  }
  
  size() {
  	return this.length;
  }
  
  isEmpty() {
  	return this.length === 0 ? true : false;
  }
  
  add(value) {
  	const node = new Node(value);
    
    let current;
    
    if(this.head === null) {
    	this.head = node;
    } else {
    	current = this.head;
      
      while(current.next) {
       	current = current.next;
      }
      current.next = node;
    }
    this.length++;
  }
}

const myLinkedList = new LinkedList();
console.log(myLinkedList.isEmpty())