posp/sorted-linked-list

v1.1 2023-06-29 13:38 UTC

This package is auto-updated.

Last update: 2024-05-05 09:51:11 UTC


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