<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
adambenovic / shipmonk-sorted-linked-list example snippets
use AdamBenovic\SortedLinkedList\SortedLinkedList;
// Just insert values -- the type is detected automatically
$list = new SortedLinkedList();
$list->insert(42);
$list->insert(7);
$list->insert(15);
$list->toArray(); // [7, 15, 42]
$list->first(); // 7
$list->last(); // 42
$list = new SortedLinkedList();
$list->insert(1); // OK -- type locked to "integer"
$list->insert(2); // OK
$list->insert('hello'); // throws TypeMismatchException
use AdamBenovic\SortedLinkedList\SortedLinkedList;
use AdamBenovic\SortedLinkedList\ValueType;
// Auto-detect type from first insert
$list = new SortedLinkedList();
// Pre-declare the type (rejects wrong-type values even before first insert)
$ints = new SortedLinkedList(ValueType::Integer);
$strings = new SortedLinkedList(ValueType::String);
// Factory method -- creates a pre-populated sorted list
$list = SortedLinkedList::of(3, 1, 4, 1, 5); // [1, 1, 3, 4, 5]
$list = SortedLinkedList::of('cherry', 'apple'); // ['apple', 'cherry']
use AdamBenovic\SortedLinkedList\IntSortedLinkedList;
use AdamBenovic\SortedLinkedList\StringSortedLinkedList;
$ints = new IntSortedLinkedList(); // first() returns int
$strings = new StringSortedLinkedList(); // first() returns string