Code Monkey home page Code Monkey logo

heapjs's Introduction

Binary heap data structure implementation in Javascript.

Usage:

Create heap:

var myHeap = new Heap();

Add element in heap:

myHeap.insert(object);

//Where "object" is an object that has the "p" property, which means its priority, for example object.p = 10
//The smaller the "p" value, the higher the priority. If objectA.p = 2, objectB.p = 21, then objectA override objectB.

Get from the heap element with the highest priority:

myHeap.extract()

Peek element with the highest priority:

myHeap.peekMin();

Get heap as an array, in which objects are sorted by priority (high priority objects are in the beginning of the array):

var arr = myHeap.getSortedArray();


---

More about binary heap:

https://en.wikipedia.org/wiki/Binary_heap
https://www.cs.cmu.edu/~adamchik/15-121/lectures/Binary%20Heaps/heaps.html
Binary heap


---

Реализация структуры данных бинарная куча на Javascript.

Использование:

Создать кучу:

var myHeap = new Heap();

Добавить элемент в кучу:

myHeap.insert(object);
//Где object - объект, имеющий свойство "p", означающее его приоритет, например object.p = 10
//Чем меньше значение p, тем выше приоритет. Если objectA.p = 2, objectB.p = 21, то objectA приоритетнее objectB.

Взять из кучи элемент с наибольшим приоритетом:

myHeap.extract()

Посмотреть элемент с наибольшим приоритетом:

myHeap.peekMin();

Получить кучу в виде массива, в котором все объекты отсортированы по приоритету (с высоким в начале массива):

var arr = myHeap.getSortedArray();

heapjs's People

Contributors

baka9k avatar

Stargazers

 avatar

Watchers

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