PHP code example of frowhy / algorithm

1. Go to this page and download the library: Download frowhy/algorithm library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

frowhy / algorithm example snippets


use Frowhy\Algorithm\Algorithm;

$i = 0; $i < $total; $i++) {
    $arr[] = rand(-10000, 10000);
}

$quickSort     = Algorithm::quickSort($arr);
$bubbleSort    = Algorithm::bubbleSort($arr);
$selectionSort = Algorithm::selectionSort($arr);
$insertionSort = Algorithm::insertionSort($arr);
$shellSort     = Algorithm::shellSort($arr);
$mergeSort     = Algorithm::mergeSort($arr);
$countingSort  = Algorithm::countingSort($arr);
$heapSort      = Algorithm::heapSort($arr);

print_r([
            '原数组'  => $arr,
            '快速排序' => $quickSort,
            '冒泡排序' => $bubbleSort,
            '选择排序' => $selectionSort,
            '插值排序' => $insertionSort,
            '希尔排序' => $shellSort,
            '归并排序' => $mergeSort,
            '计算排序' => $countingSort,
            '堆排序'  => $heapSort,
        ]);