antindehoda/sort-library

dev-master 2019-05-05 20:41 UTC

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

  1. Create the sorting strategy you need.
    $increaseStrategy = new IncreaseSorter();
  1. Create Sorter object
    $sorter = new Sorter($increaseStrategy);
  1. If you need to change strategy on the fly, you can do it using the method setStrategy.
    $decreaseStrategy = new DecreaseSorter();
    $sorter->setStrategy($decreaseStrategy);
  1. Sort the array. The method sort of the Sorter object returns a sorted array.
    $sorter->sort($array)

License

license

This project is released under the terms of the BSD-3-Clause license.

Copyright (c) 2019, Anton Degoda