posp / sorted-linked-list
SortedLinkedList
v1.1
2023-06-29 13:38 UTC
Requires
- php: >=8.1.0
Requires (Dev)
- consistence-community/coding-standard: ^3.11
- php-parallel-lint/php-parallel-lint: 1.3.2
- phpstan/phpstan: ^1.10
- phpstan/phpstan-phpunit: ^1.3
- phpstan/phpstan-strict-rules: ^1.5
- phpunit/phpunit: ^10.2
README
composer require posp/sorted-linked-list
Usage
<?php require __DIR__.'/vendor/autoload.php'; use Posp\SortedLinkedList\SortedLinkedList; $sortedLinkedList = new SortedLinkedList();
Default sorting mode is ascending, if you want descending list:
$sortedLinkedList = new SortedLinkedList(SortedLinkedList::SORT_DESC);
Adding items:
$sortedLinkedList->addItem(1); // 1 $sortedLinkedList->addItem(3); // 1->3 $sortedLinkedList->addItem(2); // 1->2->3
Removing items:
$sortedLinkedList->removeItem(2); // 1->3
SortedLinkedList
implements both Countable and Iterator interfaces:
$sortedLinkedList = new SortedLinkedList(); $sortedLinkedList->addItem(1); $sortedLinkedList->addItem(3); echo count($sortedLinkedList); // 2 foreach($sortedLinkedList as $item) { echo $item; }
Tools
Run tests: composer test
Run PhpStan: composer phpstan
Run coding standards: composer cs