1. PHP
Copy codeThe Code is as follows: <? Php
$ Unsorted = array );
Function quicksort ($ array)
{
If (count ($ array) = 0)
Return array ();
$ Dependencies = $ array [0];
$ Left = $ right = array ();
For ($ I = 1; $ I <count ($ array); $ I ++ ){
If ($ array [$ I] <$ struct)
$ Left [] = $ array [$ I];
Else
$ Right [] = $ array [$ I];
}
Return array_merge (quicksort ($ left), array ($ rows), quicksort ($ right ));
}
$ Sorted = quicksort ($ unsorted );
Print_r ($ sorted );
2. JavaScript
Copy codeThe Code is as follows: var a = [,];
Function quicksort (arr)
{
If (arr. length = 0)
Return [];
Var left = new Array ();
Var right = new Array ();
Var callback = arr [0];
For (var I = 1; I <arr. length; I ++ ){
If (arr [I] <strong ){
Left. push (arr [I]);
} Else {
Right. push (arr [I]);
}
}
Return quicksort (left). concat (rows, quicksort (right ));
}
Console. log (quicksort ());
Note that the first condition statement is very important! In PHP, the COUNT function returns a NULL value, an empty array, or 0 instead. You can use it like count ($ array) <2.Copy codeThe Code is as follows: if (count ($ array) <2)
Return $ array;
You cannot use it in JavaScript because an "empty" array is passed as a parameter for the 'undefined' value. Therefore, the preceding conditions must be included:Copy codeThe Code is as follows: // this will result with an error
If (arr. length <2)
Return arr;