- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Karthikeya Boyini has Published 2383 Articles
karthikeya Boyini
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. ... Read More
karthikeya Boyini
416 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 tail and return.If not, then we'll iterate to the ... Read More
karthikeya Boyini
403 Views
Here is the complete implementation of the DoublyLinkedList Class −Exampleclass DoublyLinkedList { constructor() { this.head = null; this.tail = null; this.length = 0; } insert(data, position = this.length) { let node = new this.Node(data); ... Read More
karthikeya Boyini
194 Views
Dequeuing elements from a PriorityQueue means removing the element of the highest priority. We are storing the elements with the highest priority at the end of the array, we can simply pop it to dequeue it.Hence, we can implement the dequeue function as follows − Exampledequeue() { // Check if ... Read More
karthikeya Boyini
74 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 ... Read More
karthikeya Boyini
219 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; ... Read More
karthikeya Boyini
251 Views
Enqueuing elements to a Queue means adding them to the end of the array. We are taking the end of the container array to be the tail of the queue as we'll perform all insertions operations with respect to it.So we can implement the enqueue function as follows −Exampleenqueue(element) { ... Read More
karthikeya Boyini
395 Views
Peeking a Queue means getting the value at the head of the Queue. So we can implement the peek function as follows − EXamplepeek() { if (isEmpty()) { console.log("Queue Underflow!"); return; } return this.container[0]; }You can check if this function is working ... Read More
karthikeya Boyini
167 Views
Here is the complete implementation of the Queue class −Exampleclass Queue { constructor(maxSize) { // Set default max size if not provided if (isNaN(maxSize)) { maxSize = 10; } this.maxSize = maxSize; ... Read More