• 0

Javascript linked list example

Challenge Problem :

Implement LinkedList in javascript, with a following method:

ll-min
  • insertNodeAtTail - adds a node to the tail of a linked list.
  • deleteNode - delets a node from the linked list and updates the list.

This post is the pre-requisite for the following examples.

Solution :

ES6 version of the solution


Non-ES6 version of the solution


Advantages :

  • Dynamic data structure, can create new nodes while the program is running.
  • Insertion and deletion node operations are easily implemented.
  • Linear data structures such as stacks and queues are easily executed with a linked list.
  • They can reduce access time and may expand in real time without memory overhead.

Disadvantages :

  • They have a tendency to use more memory due to extra property next to point to the next node.
  • Nodes in a linked list must be read in order from the beginning as linked lists are inherently sequential access.
  • Difficulties arise in linked lists when it comes to reverse traversing. For instance, singly linked lists are cumbersome to navigate backwards and while doubly linked lists are somewhat easier to read, memory is wasted in allocating space for a property back.

Further Reading