
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10483 Articles for Web Development

2K+ Views
Removing an element is very easy in a linked list. We just need to get rid of the node we want to remove, ie, lose its reference. There are 3 cases we need to consider −Removing an element from head: In this case, we can simply assign head = head.next. This way we'll lose the reference of the first element. And out head will start pointing to the second element. Removing an element from the tail: In this case, we can simply assign the node.next of second last node to be null and we'll get rid of the last element from ... Read More

1K+ Views
We need to create a function insert(data, position) that inserts data at given position in the linked list. We'll perform the following steps −Create a new NodeCheck if the list is empty. If it then adds the node to head and return.If not, then we'll iterate to the position we want to insert it to using currElem. We iterate a linked list by making currElem equal to currElem.next.Then we'll make node point to the next node in the list. This is to keep track of the rest of the list.Finally, we break the link from currElem to rest of the ... Read More

301 Views
Let's start by defining a simple class with a constructor that initializes the head to null. We'll also define another structure on the prototype of the LinkedList class that'll represent each node in the linked list.Exampleclass LinkedList { constructor() { this.head = null; this.length = 0; } } LinkedList.prototype.Node = class { constructor(data) { this.data = data; this.next = null; } }Let's also create a display function that'll help us see how our list looks like. This function works as follows.It starts from the head.It iterates ... Read More

190 Views
Following are the basic operations supported by a list.Insertion − add an element at the beginning of the list.Deletion − delete an element at the beginning of the list.Display − displaying the complete list.Search − search an element using given key.Delete − delete an element using given key.

1K+ Views
In this article, we are going to discuss various types of linked lists in JavaScript. A linked list is a sequential data structure that stores data dynamically. Since, this data structure is not indexed, the data can be added and removed as seen fit. This will reduce the wastage of memory storage. There are various types of linked list. They are as follows − Simple Linked List − Item Navigation is forward only. Doubly Linked List − Items can be navigated forward and backward way. Circular Linked List − Last item contains link of the first element as next ... Read More

316 Views
Linked List is an ordered collection of data elements. In linked list the data will be represented in Nodes. Node has two parts, the first part will be holding the data of the element and second part of the node (pointer) will store the address of the very next node. In linked list elements are stored in a sequential manner. Operations in Linked List There are several operations in Linked list, which are adding a node, deleting a node and searching a node. which are detailed in the below scenarios. Creating a Node Let’s see the scenario of linked list ... Read More

751 Views
In this article, we are going to discuss the Linked List data structure in JavaScript. A linked-list is a sequence of data structures which are connected together via links. Linked List is a sequence of links which contains items. Each link contains a connection to another link. It is one of the most used Data structures. There are some terms we'll be using when creating linked lists. Node − This represents each element in the linked list. It consists of 2 parts, data and next. Data contains the data we intend to store, while next contains the reference to the ... Read More

215 Views
Here is the complete implementation of the PriorityQueue class −Exampleclass PriorityQueue { constructor(maxSize) { // Set default max size if not provided if (isNaN(maxSize)) { maxSize = 10; } this.maxSize = maxSize; // Init an array that'll contain the queue values. this.container = []; } // Helper function to display all values while developing display() { console.log(this.container); } // Checks if queue is empty isEmpty() { ... Read More

141 Views
We can clear the contents just by reassigning the container element to an empty array. For example, clear() { this.container = []; }ExampleYou can check if this function is working fine using − let q = new PriorityQueue(4); q.enqueue("Hello", 3); q.enqueue("World", 2); q.enqueue("Foo", 8); q.display(); q.clear(); q.display();OutputThis will give the output −[ { data: 'World', priority: 2 }, { data: 'Hello', priority: 3 }, { data: 'Foo', priority: 8 } ] [ ]

139 Views
Peeking a PriorityQueue means getting the value with the highest priority without removing it. So we can implement the peek function as follows &minusl Examplepeek() { if (isEmpty()) { console.log("Queue Underflow!"); return; } return this.container[this.container.length - 1]; }You can check if this function is working fine using − Examplelet q = new PriorityQueue(4); q.enqueue("Hello", 3); q.enqueue("World", 2); q.enqueue("Foo", 8); console.log(q.peek()); q.display();OutputThis will give the output −{ data: 'Foo', priority: 8 } [ { data: 'World', priority: 2 }, { data: 'Hello', priority: 3 }, { data: 'Foo', priority: 8 } ]As ... Read More