Javascript : Linked List

Javascript Interview Question: Linked List

Posted by Jack Furr on June 22, 2018

Linked List

A few days ago I was talking to another developer and he asked me "Have you ever created a linked list in Javscript?" I had to stop and think about it for a while. I had only writen a linked list in c/c++ many years ago. I had never found a need for a linked list in Javscript.

To start, I had to create the data structure and define the Node and the LinkedList to manage the nodes.

Adding a Node

Time Complexity: O(n)

Prepending a Node

Time Complexity: O(1)

Reversing

Time Complexity: O(n)
Space Complexity: O(1)

Reversing Recursivly

Time Complexity: O(n)
Space Complexity: O(1)

Complete Example

Thanks for checking out this short code review, and good luck!