Samual Sam has Published 2492 Articles

The Set Class in Javascript

Samual Sam

Samual Sam

Updated on 15-Jun-2020 09:30:31

75 Views

Here is the complete implementation of the MySet class. Exampleclass MySet {    constructor() {       this.container = {};    }    display() {       console.log(this.container);    }    has(val) {       return this.container.hasOwnProperty(val);    }    add(val) {       if (!this.has(val)) { ... Read More

The Linked List Class in Javascript

Samual Sam

Samual Sam

Updated on 15-Jun-2020 09:28:03

106 Views

Here is the complete implementation of the LinkedList class −  Exampleclass LinkedList {    constructor() {       this.head = null;       this.length = 0;    }    insert(data, position = this.length) {       let node = new this.Node(data);       if (this.head === ... Read More

Creating a Doubly Linked List using Javascript

Samual Sam

Samual Sam

Updated on 15-Jun-2020 09:26:17

221 Views

Lets start by defining a simple class with a constructor that initializes the head and tail to null. We'll also define another structure on the prototype of the DoublyLinkedList class that'll represent each node in the linked list. Exampleclass LinkedList {    constructor() {       this.head = null;   ... Read More

Removing Elements from a Double Linked List using Javascript

Samual Sam

Samual Sam

Updated on 15-Jun-2020 09:22:15

438 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

Circular linked lists in Javascript

Samual Sam

Samual Sam

Updated on 15-Jun-2020 09:19:04

424 Views

Circular Linked List is a variation of the Linked list in which the first element points to the last element and the last element points to the first element. Both Singly Linked List and Doubly Linked List can be made into a circular linked list.

Doubly Linked List as Circular in Javascript

Samual Sam

Samual Sam

Updated on 15-Jun-2020 09:17:59

146 Views

In the doubly linked list, the next pointer of the last node points to the first node and the previous pointer of the first node points to the last node making the circular in both directions.Insertions and deletions in a circular linked list are the same as other linked lists. ... Read More

Peeking elements from a PriorityQueue using JavaScript

Samual Sam

Samual Sam

Updated on 15-Jun-2020 09:14:15

100 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 ... Read More

The PriorityQueue Class in Javascript

Samual Sam

Samual Sam

Updated on 15-Jun-2020 09:10:49

121 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;   ... Read More

Basic Operations supported by a list in Javascript

Samual Sam

Samual Sam

Updated on 15-Jun-2020 09:08:53

110 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.

Add elements to a linked list using Javascript

Samual Sam

Samual Sam

Updated on 15-Jun-2020 09:06:10

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 ... Read More

Advertisements