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.]
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 Singly Linked List. Go to the editor
2. Write a JavaScript program to create a singly linked list of n nodes and display it in reverse order. Go to the editor
3. Write a JavaScript program to create a singly linked list of n nodes and count the number of nodes. Go to the editor
4. Write a JavaScript program to insert a new node at any position of a Singly Linked List. Go to the editor
5. Write a JavaScript program to insert a new node at the beginning of a Singly Linked List. Go to the editor
6. Write a JavaScript program to insert a new node at the end of a Singly Linked List. Go to the editor
7. Write a JavaScript program to get a node in an existing singly linked list. Go to the editor
8. Write a JavaScript program to find the first index that matches a given element. Return -1 for no matching. Go to the editor
9. Write a JavaScript program to check whether a single linked list is empty or not. Return true otherwise false. Go to the editor
10. Write a JavaScript program to empty a singly linked list by pointing the head towards null. Go to the editor
11. Write a JavaScript program that removes the node from the singly linked list at the specified index. Go to the editor
12. Write a JavaScript program that calculates the size of a Singly Linked list. Go to the editor
13. Write a JavaScript program that removes the first element from a Singly Linked list. Go to the editor
14. Write a JavaScript program that removes the tail element from a Singly Linked list. Go to the editor
15. Write a JavaScript program to convert a Singly Linked list into an array and returns it. Go to the editor
16. Write a JavaScript program to convert a Singly Linked list into a string and returns it. Go to the editor
17. Write a JavaScript program to get the index of an element in a Singly Linked list. Go to the editor
18. Write a JavaScript program to check if an element is present in the Singly Linked list. Go to the editor
JavaScript Data Structures: Doubly Linked List [10 exercises with solution]
1. Write a JavaScript program to create and display Doubly Linked Lists. Go to the editor
2. Write a JavaScript program to create a Doubly Linked Lists of n nodes and count the number of nodes. Go to the editor
3. Write a JavaScript program to check whether a Doubly Linked Lists is empty or not. Return true otherwise false. Go to the editor
4. Write a JavaScript program to get the head and tail of a Doubly Linked Lists. Go to the editor
5. Write a JavaScript program to insert a new node at any position of a Doubly Linked List. Go to the editor
6. Write a JavaScript program to insert a new node at the beginning of a Doubly Linked List. Go to the editor
7. Write a JavaScript program to insert a new node at the end of a Doubly Linked List. Go to the editor
8. Write a JavaScript program to get the value of a node at a given position in a Doubly Linked List. Go to the editor
9. Write a JavaScript program to create a Doubly Linked lists of n nodes and display it in reverse order. Go to the editor
10. Write a JavaScript program to convert a Doubly Linked lists into an array and returns it. Go to the editor
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.
JavaScript: Tips of the Day
Shorten an array using its length property
A great way of shortening an array is by redefining its length property.
let array = [0, 1, 2, 3, 4, 5, 6, 6, 8, 9] array.length = 4 // Result: [0, 1, 2, 3]
Important to know though is that this is a destructive way of changing the array. This means you lose all the other values that used to be in the array.
Ref: https://bit.ly/2LBj213
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises