Skip to content

anilozmen/computer-science-algorithms-in-php

Repository files navigation

Computer Science Algorithms in PHP

<?php

use CS\Sort;
use CS\Sort\BubbleSort;

(new Sort)->sort([5, 7, 3, 2, 9, 0, 1, 6, 8, 4], new BubbleSort);
<?php

use \CS\Sort;
use \CS\Sort\InsertionSort;

(new Sort)->sort([5, 7, 3, 2, 9, 0, 1, 6, 8, 4], new InsertionSort);
<?php

use \CS\Sort;
use \CS\Sort\MergeSort;

(new Sort)->sort([5, 7, 3, 2, 9, 0, 1, 6, 8, 4], new MergeSort);
<?php

use \CS\Sort;
use \CS\Sort\QuickSort;

(new Sort)->sort([5, 7, 3, 2, 9, 0, 1, 6, 8, 4], new QuickSort);
<?php

use \CS\Sort;
use \CS\Sort\RadixSort;

(new Sort)->sort([5, 7, 3, 2, 9, 0, 1, 6, 8, 4], new RadixSort);
<?php

use \CS\Search;
use \CS\Search\LinearSearch;

$array = [
    ['id' => 1, 'name' => 'Joe'],
    ['id' => 3, 'name' => 'Olivia'],
    ['id' => 5, 'name' => 'Emma'],
    ['id' => 6, 'name' => 'Oliver'],
    ['id' => 10, 'name' => 'Liam'],
    ['id' => 12, 'name' => 'John'],
    ['id' => 13, 'name' => 'James'],
    ['id' => 15, 'name' => 'Sophia'],
    ['id' => 17, 'name' => 'Benjamin'],
    ['id' => 18, 'name' => 'Ryan'],
    ['id' => 19, 'name' => 'Ivy'],
    ['id' => 21, 'name' => 'Alice'],
    ['id' => 23, 'name' => 'Max'],
    ['id' => 24, 'name' => 'Simon'],
];

(new Search)->sort($array, new LinearSearch);
<?php

use \CS\Search;
use \CS\Search\BinarySearch;

$array = [
    ['id' => 1, 'name' => 'Joe'],
    ['id' => 3, 'name' => 'Olivia'],
    ['id' => 5, 'name' => 'Emma'],
    ['id' => 6, 'name' => 'Oliver'],
    ['id' => 10, 'name' => 'Liam'],
    ['id' => 12, 'name' => 'John'],
    ['id' => 13, 'name' => 'James'],
    ['id' => 15, 'name' => 'Sophia'],
    ['id' => 17, 'name' => 'Benjamin'],
    ['id' => 18, 'name' => 'Ryan'],
    ['id' => 19, 'name' => 'Ivy'],
    ['id' => 21, 'name' => 'Alice'],
    ['id' => 23, 'name' => 'Max'],
    ['id' => 24, 'name' => 'Simon'],
];

(new Search)->sort($array, new BinarySearch);

About

Computer Science Algorithms in PHP

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages