0.1.9 • Published 2 years ago

data_structures_and_algorithms_javascript v0.1.9

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Introduction

A useful library to learn and use data structure and algorithm in JS & TS

List

  import { List } from "data_structures_and_algorithms_javascript"

  const moviesList = new List();
  moviesList.append('Interstellar');
  moviesList.append('Shutter Island');
  moviesList.append('Inception');
  console.log(moviesList.toString()) // ['Interstellar', 'Shutter Island', 'Inception']

  moviesList.clear();
  console.log(moviesList.toString()) // []

  moviesList.remove('Inception');
  console.log(moviesList.toString()) // ['Interstellar', 'Shutter Island']

Stack

  import { Stack } from "data_structures_and_algorithms_javascript"

  const tasksStack = new Stack(); // []
  tasksStack.push('To Do 1'); // ['To Do 1']
  tasksStack.push('To Do 2'); // ['To Do 1', 'To Do 2']
  tasksStack.push('To Do 3'); // ['To Do 1', 'To Do 2', 'To Do 3']
  const task1 = tasksStack.pop(); // task = 'To Do 3' & tasksStack = ['To Do 1','To Do 2']
  const task2 = tasksStack.peak(); // task = 'To Do 2' & tasksStack = ['To Do 1','To Do 2']
  tasksStack.length() // 2

Queue

  import { Queue } from "data_structures_and_algorithms_javascript"

  const people = new Queue(); // []
  people.enqueue('Person 1'); // ['Person 1']
  people.enqueue('Person 2'); // ['Person 1', 'Person 2']
  people.enqueue('Person 3'); // ['Person 1', 'Person 2', 'Person 3']
  people.length() // 3
  const person1 = people.dequeue(); // 'Person 1'
  people.enqueue(person1);  // ['Person 2', 'Person 3', 'Person 1']
  people.back() // 'Person 1'
  people.front() // 'Person 2'
  people.empty() // false

LinkedList

  import { LinkedList } from "data_structures_and_algorithms_javascript"

  const cities = new LinkedList();
  cities.insert('Tehran', 'head');
  cities.insert('LA', 'Tehran');
  cities.insert('London', 'LA');
  cities.insert('Amsterdam', 'London');
  cities.find('Amsterdam') // Node {element: "Amsterdam", nextElement: null}
  cities.remove('Amsterdam');
  cities.find('Amsterdam') // null
  cities.findPrevious('Amsterdam') // Node {element: "London", nextElement: null}

Dictionary

  import { Dictionary } from "data_structures_and_algorithms_javascript"

  const peopleHeights = new Dictionary(); // {}
  peopleHeights.add('Komeil', 184); // {Komeil: 184}
  peopleHeights.add('Tara', 165); // {Tara: 165}
  peopleHeights.find('Komeil'); // 184
  peopleHeights.length(); // 2
  peopleHeights.remove('Komeil'); 
  peopleHeights.find('Komeil') // undefined
  peopleHeights.clear(); // {}
0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago