<? PHP /* ** PHP quick sorting */ $ Arr = Array (,) ); Function Quick ( $ Array ){ If ( Count ( $ Array ) <= 1) Return $ Array ; $ K = $ Array [0 ]; $ Left = Array (); $ Right = Array (); For ( $ I = 1; $ I < Count ( $ Array ); $ I ++ ){ If ( $ Array [ $ I ] <= $ K ){ $ Left [] = $ Array [ $ I ];} Else { $ Right [] =$ Array [ $ I ] ;}} $ Left = Quick ( $ Left ); $ Right = Quick ( $ Right ); Return Array_merge ( $ Left , Array ( $ K ),$ Right );} Print_r (Quick ( $ Arr )); ?>
The core idea is to obtain the first element of the array to be sorted each time. If the value is greater than other elements in the array, it is placed on the left or on the right.
Then, the set on the left is sorted in the same order until only 0 ~ exists on the left ~ 1 element. (0 indicates that the first element of this sorting is the smallest. 1 indicates that only one element is greater than others)