Fast sorting
<? Php
Function quicksort ($ str ){
If (count ($ str) <= 1) return $ str; // if the number is not big, return directly
$ Key = $ str [0]; // obtain a value for comparison later;
$ Left_arr = array ();
$ Right_arr = array ();
For ($ I = 1; $ I <count ($ str); $ I ++) {// place a value greater than $ key on the right and a small value on the left;
If ($ str [$ I] <= $ key)
$ Left_arr [] = $ str [$ I];
Else
$ Right_arr [] = $ str [$ I];
}
$ Left_arr = quicksort ($ left_arr); // recursion;
$ Right_arr = quicksort ($ right_arr );
Return array_merge ($ left_arr, array ($ key), $ right_arr); // combines the left and right values into an array;
} // The following is the test
$ Str = array (, 0 );
Print_r (quicksort ($ str ));
?>
Bubble Sorting
<? Php
Function bubbingSort (array $ array)
{
For ($ I = 0, $ len = count ($ array)-1; $ I <$ len; ++ $ I)
{
For ($ j = $ len; $ j> $ I; -- $ j)
{
If ($ array [$ j] <$ array [$ J-1])
{
$ Temp = $ array [$ j];
$ Array [$ j] = $ array [$ J-1];
$ Array [$ J-1] = $ temp;
}
}
}
Return $ array;
}
Print '<pre> ';
Print_r (bubbingSort (array (, 9 )));
Print '</pre> ';