antindehoda / sort-library
Sorting library
dev-master
2019-05-05 20:41 UTC
Requires
- php: >=7.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.13
This package is auto-updated.
Last update: 2024-07-06 08:44:28 UTC
README
SortLibrary
Library sorting arrays of numbers and arrays of strings.
Contains two standard implementations of sorting algorithms: from large to small (DecreaseSorter
) and from small to large (IncreaseSorter
).
Also implemented the design pattern "Null Object" (NullObjectSorter
).
Installation
To install the library, run this command:
$ composer require antindehoda/sort-library
Usage
- Create the sorting strategy you need.
$increaseStrategy = new IncreaseSorter();
- Create Sorter object
$sorter = new Sorter($increaseStrategy);
- If you need to change strategy on the fly, you can do it using the method
setStrategy
.
$decreaseStrategy = new DecreaseSorter(); $sorter->setStrategy($decreaseStrategy);
- Sort the array. The method
sort
of the Sorter object returns a sorted array.
$sorter->sort($array)
License
This project is released under the terms of the BSD-3-Clause license.
Copyright (c) 2019, Anton Degoda