From ecfcf6e30b800ff1b41b18733a12c3c579274abd Mon Sep 17 00:00:00 2001 From: Guillermo Laseca Date: Mon, 7 Oct 2019 00:30:10 +0200 Subject: [PATCH] Quick sort in PHP --- Algorithms/sorting/quick_sort.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Algorithms/sorting/quick_sort.php diff --git a/Algorithms/sorting/quick_sort.php b/Algorithms/sorting/quick_sort.php new file mode 100644 index 0000000..f629ed6 --- /dev/null +++ b/Algorithms/sorting/quick_sort.php @@ -0,0 +1,23 @@ + $pivot){ + $right[] = $val; + } + } + return array_merge(quick_sort($left),array($pivot_key=>$pivot),quick_sort($right)); +} + +$array = array(4, 3, 0, 8, -1, 5, 1); +echo 'Original array : '.implode(',',$array).'\n'; +$sorted_array = quick_sort($array); +echo 'Sorted array : '.implode(',',$sorted_array);