astepanov/otus-php-example-sorter

该包的最新版本(dev-master)没有可用的许可证信息。

简单排序库

dev-master 2019-03-14 09:10 UTC

This package is auto-updated.

Last update: 2024-09-14 22:01:39 UTC


README

这是一个简单的排序库。

安装

您可以通过git获取

$ git clone https://github.com/lenniDespero/otus-php-example-sorter.git

或者通过composer

$ composer require astepanov/otus-php-example-sorter @dev

使用

<?php
    use Otus\Lessons\Lesson4\Sorter;
    $example = new Sorter();
    $array = [1, 4, 3, 5, 2, 6];
    echo "Array in: " . implode($array, ', ') . PHP_EOL; // Array in: 1, 4, 3, 5, 2, 6
    $example->setSortStyle(SORT_INSERT);
    echo "Array out: " . implode($example->sort($array), ', ') . PHP_EOL; // Array out: 1, 2, 3, 4, 5, 6

异常处理

<?php
    use Otus\Lessons\Lesson4\Sorter;
    $example = new Sorter();
    echo "Sort styles: " . implode($example->getSortStyles(), ', ') . PHP_EOL; // Sort styles: SORT_BUBBLE, SORT_QUICK, SORT_INSERT
    try {
        $example->setSortStyle(WRONG_SORT);
    } catch (\Exception $ex) {
        echo $ex->getMessage() . PHP_EOL;   // Chosen sort style 'WRONG_SORT' not in supported sort styles.
                                            // Use getSortStyles() method to get list of supported sort styles
    }

示例文件夹中有更多示例。

待办事项

  • 添加更多排序样式
  • 添加测试

许可证

MIT

自由软件,太棒了!