w3resource

JavaScript Linked List - Exercises, Practice, Solution

JavaScript Data Structures: Singly Linked List [18 exercises with solution]

[An editor is available at the bottom of the page to write and execute the scripts.  Go to the editor]

From Wikipedia,
In computer science, a linked list is a linear collection of data elements whose order is not given by their physical placement in memory. Instead, each element points to the next. It is a data structure consisting of a collection of nodes which together represent a sequence. This structure allows for efficient insertion or removal of elements from any position in the sequence during iteration. A drawback of linked lists is that access time is linear. Faster access, such as random access, is not feasible. Arrays have better cache locality compared to linked lists.

1. Write a JavaScript program to create and display a Singly Linked List.

Click me to see the solution

2. Write a JavaScript program to create a singly linked list of n nodes and display it in reverse order.

Click me to see the solution

3. Write a JavaScript program to create a singly linked list of n nodes and count the number of nodes.

Click me to see the solution

4. Write a JavaScript program to insert a node at any position in a Singly Linked List.

Click me to see the solution

5. Write a JavaScript program to insert a node at the beginning of a Singly Linked List.

Click me to see the solution

6. Write a JavaScript program to insert a node at the end of a Singly Linked List.

Click me to see the solution

7. Write a JavaScript program to get a node in an existing singly linked list.

Click me to see the solution

8. Write a JavaScript program to find the first index that matches a given element. Return -1 for no matching.

Click me to see the solution

9. Write a JavaScript program to check whether a single linked list is empty or not. Return true otherwise false.

Click me to see the solution

10. Write a JavaScript program to empty a singly linked list by pointing the head towards null.

Click me to see the solution

11. Write a JavaScript program that removes the node from the singly linked list at the specified index.

Click me to see the solution

12. Write a JavaScript program that calculates the size of a Singly Linked list.

Click me to see the solution

13. Write a JavaScript program that removes the first element from a Singly Linked list.

Click me to see the solution

14. Write a JavaScript program that removes the tail element from a Singly Linked list.

Click me to see the solution

15. Write a JavaScript program to convert a Singly Linked list into an array.

Click me to see the solution

16. Write a JavaScript program to convert a Singly Linked list into a string.

Click me to see the solution

17. Write a JavaScript program to get the index of an element in a Singly Linked list.

Click me to see the solution

18. Write a JavaScript program to check if an element is present in the Singly Linked list.

Click me to see the solution

JavaScript Data Structures: Doubly Linked List [17 exercises with solution]

1. Write a JavaScript program to create and display Doubly Linked Lists.

Click me to see the solution

2. Write a JavaScript program to create a Doubly Linked Lists of n nodes and count the number of nodes.

Click me to see the solution

3. Write a JavaScript program to check whether a Doubly Linked Lists is empty or not. Return true otherwise false.

Click me to see the solution

4. Write a JavaScript program to get the head and tail of a Doubly Linked Lists.

Click me to see the solution

5. Write a JavaScript program to insert a new node at any position of a Doubly Linked List.

Click me to see the solution

6. Write a JavaScript program to insert a new node at the beginning of a Doubly Linked List.

Click me to see the solution

7. Write a JavaScript program to insert a new node at the end of a Doubly Linked List.

Click me to see the solution

8. Write a JavaScript program to get the value of a node at a given position in a Doubly Linked List.

Click me to see the solution

9. Write a JavaScript program to create a Doubly Linked lists of n nodes and display it in reverse order.

Click me to see the solution

10. Write a JavaScript program to convert a Doubly Linked lists into an array and returns it.

Click me to see the solution

11. Write a JavaScript program to convert a Doubly Linked List into a string and return it.

Click me to see the solution

12. Write a JavaScript program to get the index of an element in a Doubly Linked lists.

Click me to see the solution

13. Write a JavaScript program to check if an element is present in a Doubly Linked lists.

Click me to see the solution

14. Write a JavaScript program that removes the node from the Doubly linked lists at the specified index.

Click me to see the solution

15. Write a JavaScript program that removes the head element from a doubly Linked lists.

Click me to see the solution

16. Write a JavaScript program that removes the tail element from a doubly Linked lists.

Click me to see the solution

17. Write a JavaScript program that updates the value of a node at a specific index in a Doubly Linked list.

Click me to see the solution

More to Come !

* To run the code mouse over on Result panel and click on 'RERUN' button.*

Live Demo:

See the Pen javascript-common-editor by w3resource (@w3resource) on CodePen.


Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/javascript-exercises/linkedlist/index.php