PHP code example of posp / sorted-linked-list

1. Go to this page and download the library: Download posp/sorted-linked-list 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/ */

    

posp / sorted-linked-list example snippets



osp\SortedLinkedList\SortedLinkedList;

$sortedLinkedList = new SortedLinkedList();

$sortedLinkedList = new SortedLinkedList(SortedLinkedList::SORT_DESC);

$sortedLinkedList->addItem(1); // 1
$sortedLinkedList->addItem(3); // 1->3
$sortedLinkedList->addItem(2); // 1->2->3

$sortedLinkedList->removeItem(2); // 1->3

$sortedLinkedList = new SortedLinkedList();
$sortedLinkedList->addItem(1);
$sortedLinkedList->addItem(3);

echo count($sortedLinkedList); // 2

foreach($sortedLinkedList as $item) {
    echo $item; 
}