Giter VIP home page Giter VIP logo

data-structures-and-algorithms-javascript's Introduction

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(); // {}

data-structures-and-algorithms-javascript's People

Contributors

komeilmehranfar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.