PHPackages                             affinity4/heap - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. affinity4/heap

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

affinity4/heap
==============

Full Binary Heap implementation with maxheap, minheap and memory-efficient O(nlogn) and space-complexity of O(1) heapsort algorithm

0.0.1(1y ago)010MITPHP

Since Jul 13Pushed 1y ago1 watchersCompare

[ Source](https://github.com/affinity4/heap)[ Packagist](https://packagist.org/packages/affinity4/heap)[ RSS](/packages/affinity4-heap/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Heap Class in PHP
=================

[](#heap-class-in-php)

The `Heap` class is an implementation of a Max Heap data structure in PHP. A Heap is a complete binary tree where the value of each node is greater than or equal to the values of its children, which makes it useful for efficiently finding the maximum element.

Features
--------

[](#features)

- **Heap Construction**: Initialize the heap with an array and build a max heap.
- **Insert**: Add a new element to the heap.
- **Remove**: Remove a specific element from the heap.
- **Sort**: Perform heap sort and return the array sorted in ascending or descending order.

Installation
------------

[](#installation)

Install the `Heap` class via composer:

```
composer require affinity4/heap
```

Usage
-----

[](#usage)

Here is an example of how to use the `Heap` class:

```
