PHP code example of slimapi / data-structure

1. Go to this page and download the library: Download slimapi/data-structure 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/ */

    

slimapi / data-structure example snippets


$list = new SortedLinkedList();
$list->insert(3); // [3]
$list->insert(1); // [1, 3]
$list->insert(2); // [1, 2, 3]

$list = new SortedLinkedList(Direction::DESC);
$list->insert(3); // [3]
$list->insert(1); // [3, 1]
$list->insert(2); // [3, 2, 1]

$list->remove(2); // [3, 1]

echo $list->count(); // 2

foreach ($list->toGenerator() as $item) {
    echo $item; // Outputs 3, then 1
}