Skip to content

Latest commit

 

History

History

linked-list

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

@datastructures/linked-list ⛓

Typed with TypeScript npm version

A minimal typed implementation of a linked list. 🦄

Linked lists are a linear structure of items. Each item is a seperate object. Each item is made with a relationship to its next item.

Diagram

sequenceDiagram
  participant Node 1
  participant Node 2
  participant Node 3
  Node 1-->>Node 2: next node
  Node 2-->>Node 1: previous node
  Node 2-->>Node 3: next node
  Node 3-->>Node 2: previous node

Structure

item: { name: 'foo', data: { foo: 'bar' } },
nextItem: {
  item: { name: 'bar', data: { biz: 'baz' } },
  nextItem: null,
}

Install

npm add @datastructures/linked-list -D

Usage

import { list } from '@datastructures/linked-list'

const items = [ { name: 'foo',  data: { foo: 'bar'} }, { name: 'bar', data: { biz: 'baz', }}]
const tree = list.create(items)
// output
const arrayList = list.toArray(tree)
// array  [ { name: 'foo',  data: { foo: 'bar'} }, { name: 'bar', data: { biz: 'baz', }}]
// from here feel free to add other testable methods to satify your interviewer 🙋

API

Items

Items are optional objects constructed using an item function. Optionally, to create a list of items, an array of items can be passed into a list.create() method.

name: when adding a list a string is always required

data: a data {object} for containing useful data with a Node

ex: const node = item('foo', { foo: "bar" }); const linkedList = list.create(node)


Methods

create(items) creates a list from an array of items with a name and an optional data {object}

ex: list.create([ { name: 'foo', data: { foo: 'bar'} }, { name: 'bar', data: { biz: 'baz', }}])

toArray(items) creates an array of items with a name and an optional data {object} from a list

ex: list.toArray(someLinkedList)


Data Structures 🦄

Basic. Functional. Typed. Data Structures.

Functional typed data structures offering structure clarity and simplicity.


View other data structures.