JavaScript Implementation of the Binary Heap.
Constructs a new minimum binary heap, Minimum heap is default;
Constructs a new minimum binary heap.
Parameters:
- isMinHeap - true to use the order imposed by the given comparator; false to reverse that order
Constructs a new BinaryHeap that will use the given comparator to order its elements.
Parameters:
- capacity - the initial capacity for the heap
Constructs a new minimum binary heap with the specified initial capacity.
Parameters:
- capacity - The initial capacity for the heap. This value must be greater than zero.
Throws:
- IllegalArgumentException - if capacity is <= 0
Constructs a new BinaryHeap.
Parameters:
- capacity - the initial capacity for the heap
- isMinHeap - true to use the order imposed by the given comparator; false to reverse that order
- comparator - the comparator used to order the elements, null means use natural order
Throws:
- IllegalArgumentException - if capacity is <= 0
Clears all elements from queue.
Tests if queue is empty.
Returns:
- true if queue is empty; false otherwise.
Tests if queue is full.
Returns:
- true if queue is full; false otherwise.
Inserts an element into queue.
Parameters:
- element - the element to be inserted
Returns the element on top of heap but don't remove it.
Returns:
- the element at top of heap
Throws:
- NoSuchElementException - if isEmpty() == true
Returns the element on top of heap and remove it.
Returns:
- the element at top of heap
Throws:
- NoSuchElementException - if isEmpty() == true
Returns a string representation of this heap.
Returns:
- a string representation of this heap
Returns an iterator over this heap's elements.
Returns:
- an iterator over this heap's elements
Adds an object to this heap. Same as insert(Object).
Parameters:
- object - the object to add
Returns:
- true, always
Returns the priority element. Same as peek().
Returns:
- the priority element
Throws:
- BufferUnderflowException - if this heap is empty
Removes the priority element. Same as pop().
Returns:
- the removed priority element
Throws:
- BufferUnderflowException - if this heap is empty
Returns the number of elements in this heap.
Returns:
- the number of elements in this heap
The MIT License (MIT)