Socket
Book a DemoInstallSign in
Socket

double-linked-list-dot-js

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

double-linked-list-dot-js

Efficient and useful implementation of the double linked list structure

1.0.1
latest
Source
npmnpm
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

Double Linked List Dot Js

About The Project

Efficient and useful implementation of the double linked list structure

Getting Started

yarn add double-linked-list-dot-js # if you use yarn

npm install --save double-linked-list-dot-js # if you use npm

Usage

// Basic usage example
import {DoubleLinkedList, Node} from 'double-linked-list-dot-js';

let list = new DoubleLinkedList();

let head = new Node(2);
list.setHead(head);
console.log(list);
/* DoubleLinkedList {
  head: Node { value: 2, prev: null, next: null },
  tail: Node { value: 2, prev: null, next: null }
}
} */
list.insertAtPosition(2, new Node(5));
list.insertAtPosition(3, new Node(6));
list.insertAtPosition(4, new Node(7));
list.insertAtPosition(5, new Node(9));
console.log(list);
/*
DoubleLinkedList {
  head: <ref *1> Node {
    value: 2,
    prev: null,
    next: Node { value: 5, prev: [Circular *1], next: [Node] }
  },
  tail: <ref *2> Node {
    value: 9,
    prev: Node { value: 7, prev: [Node], next: [Circular *2] },
    next: null
  }*/
console.log(list.containsValue(2)); //true
console.log(list.containsValue(5)); //true
console.log(list.containsValue(6)); //true
console.log(list.containsValue(7)); //true
console.log(list.containsValue(9)); //true
//remove node by reference
list.removeNode(head);
console.log(list);
/*DoubleLinkedList {
  head: <ref *1> Node {
    value: 5,
    prev: null,
    next: Node { value: 6, prev: [Circular *1], next: [Node] }
  },
  tail: <ref *2> Node {
    value: 9,
    prev: Node { value: 7, prev: [Node], next: [Circular *2] },
    next: null
  }
}*/
//remove node by value
list.removeNodeWithValue(7);
console.log(list);
/*DoubleLinkedList {
  head: <ref *1> Node {
    value: 5,
    prev: null,
    next: Node { value: 6, prev: [Circular *1], next: [Node] }
  },
  tail: <ref *2> Node {
    value: 9,
    prev: Node { value: 6, prev: [Node], next: [Circular *2] },
    next: null
  }
}*/

Keywords

linked list

FAQs

Package last updated on 22 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.