How to use PHP to describe quick sorting algorithm
This article mainly shows you "how to use PHP to describe the fast sorting algorithm", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use PHP to describe quick sorting algorithm" this article.
Using PHP to describe the quick sort algorithm, can the object be an array?
Principle: quick sorting uses divide-and-conquer strategy to divide the data sequence to be sorted into two subsequences. the specific steps are as follows:
(1) pick an element from a series and call it a "benchmark".
(2) scan the series once, putting all the elements smaller than the "base" in front of the base, and all the elements larger than the "base" after the base.
(3) through recursion, each subsequence is divided into smaller sequences until the subseries of elements less than the reference value and the subsequence of elements greater than the reference value are sorted.
/ / Quick sort (array sort) function QuickSort ($arr) {$num = count ($arr); $arr; for ($iSequence1) {$left = QuickSort ($left);} $new_arr = $left; $new_arr [] = $arr [0]; if ($r > 1) {$right = QuickSort ($right);} for ($iS0 / QuickSort)