PHP code example of rulinski / sorted-linked-list

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

    

rulinski / sorted-linked-list example snippets


use Rulinski\SortedLinkedList\SortedLinkedList;

$list = new SortedLinkedList(SortedLinkedList::TYPE_INT);

$list->add(5);
$list->add(1);
$list->add(3);

$list->toArray();     // [1, 3, 5]
(string) $list;        // "[1, 3, 5]"
$list->contains(3);    // true
$list->first();        // 1
$list->last();         // 5
count($list);          // 3

foreach ($list as $value) {
    // 1, 3, 5
}

$list->remove(3);      // true
$list->toArray();      // [1, 5]

$strings = new SortedLinkedList(SortedLinkedList::TYPE_STRING);
$strings->add('banana');
$strings->add('apple');

$strings->toArray();   // ['apple', 'banana']

$strings->add(42);     // throws InvalidValueTypeException