PHP code example of thomaslarsson / priorityqueue

1. Go to this page and download the library: Download thomaslarsson/priorityqueue library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

thomaslarsson / priorityqueue example snippets


// Require composer's autoload
 package's namespace
use ThomasLarsson\PriorityQueue\MinPriorityQueue as MinPriorityQueue,
    ThomasLarsson\PriorityQueue\MaxPriorityQueue as MaxPriorityQueue;

// Create a ascending queue (Use the package's namespace unless you aliased it)
$ascendingQueue = new MinPriorityQueue();

// ... OR a descending queue.
$descendingQueue = new MaxPriorityQueue(); // A decending queue

// Create some data sorted descending (Just to illustrate that it's working)
$ascendingQueue->insert(4, 0);
$ascendingQueue->insert(3, 0);
$ascendingQueue->insert(2, 0);
$ascendingQueue->insert(1, 0);
$ascendingQueue->insert(0, 0);

// Display the sorted result
foreach ( $ascendingQueue as $value )
{
    echo $value . "\n";
}