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.
2. Write a JavaScript program to create a singly linked list of n nodes and display it in reverse order.
3. Write a JavaScript program to create a singly linked list of n nodes and count the number of nodes.
4. Write a JavaScript program to insert a node at any position in a Singly Linked List.
5. Write a JavaScript program to insert a node at the beginning of a Singly Linked List.
6. Write a JavaScript program to insert a node at the end of a Singly Linked List.
7. Write a JavaScript program to get a node in an existing singly linked list.
8. Write a JavaScript program to find the first index that matches a given element. Return -1 for no matching.
9. Write a JavaScript program to check whether a single linked list is empty or not. Return true otherwise false.
10. Write a JavaScript program to empty a singly linked list by pointing the head towards null.
11. Write a JavaScript program that removes the node from the singly linked list at the specified index.
12. Write a JavaScript program that calculates the size of a Singly Linked list.
13. Write a JavaScript program that removes the first element from a Singly Linked list.
14. Write a JavaScript program that removes the tail element from a Singly Linked list.
15. Write a JavaScript program to convert a Singly Linked list into an array.
16. Write a JavaScript program to convert a Singly Linked list into a string.
17. Write a JavaScript program to get the index of an element in a Singly Linked list.
18. Write a JavaScript program to check if an element is present in the Singly Linked list.
JavaScript Data Structures: Doubly Linked List [17 exercises with solution]
1. Write a JavaScript program to create and display Doubly Linked Lists.
2. Write a JavaScript program to create a Doubly Linked Lists of n nodes and count the number of nodes.
3. Write a JavaScript program to check whether a Doubly Linked Lists is empty or not. Return true otherwise false.
4. Write a JavaScript program to get the head and tail of a Doubly Linked Lists.
5. Write a JavaScript program to insert a new node at any position of a Doubly Linked List.
6. Write a JavaScript program to insert a new node at the beginning of a Doubly Linked List.
7. Write a JavaScript program to insert a new node at the end of a Doubly Linked List.
8. Write a JavaScript program to get the value of a node at a given position in a Doubly Linked List.
9. Write a JavaScript program to create a Doubly Linked lists of n nodes and display it in reverse order.
10. Write a JavaScript program to convert a Doubly Linked lists into an array and returns it.
11. Write a JavaScript program to convert a Doubly Linked List into a string and return it.
12. Write a JavaScript program to get the index of an element in a Doubly Linked lists.
13. Write a JavaScript program to check if an element is present in a Doubly Linked lists.
14. Write a JavaScript program that removes the node from the Doubly linked lists at the specified index.
15. Write a JavaScript program that removes the head element from a doubly Linked lists.
16. Write a JavaScript program that removes the tail element from a doubly Linked lists.
17. Write a JavaScript program that updates the value of a node at a specific index in a Doubly Linked list.
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.
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
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics