Php selects the sorting algorithm implementation code
- // Select the sorting function
- // Use references to reduce memory consumption
- // Finishing: bbs.it-home.org
- Function & select (& $ arr ){
- $ Count = count ($ arr );
- If ($ count> 1 ){
- For ($ I = 0; $ I <$ count-1; $ I ++ ){
- $ K = $ I;
- For ($ j = $ I + 1; $ j <$ count; $ j ++ ){
- If ($ arr [$ j] <$ arr [$ k]) {
- $ K = $ j;
- }
- }
- If ($ k! = $ I ){
- $ Tmp = $ arr [$ k];
- $ Arr [$ k] = $ arr [$ I];
- $ Arr [$ I] = $ tmp;
- }
- }
- }
- Return $ arr;
- }
- // Print the array function
- Function printArr (& $ arr ){
- Echo"
"; - print_r($arr);
- echo "
";
- }
- // Start the test
- // Randomly assign ten values to the array
- For ($ I = 0; $ I <10; $ I ++ ){
- $ TestArr [] = rand (10,100 );
- }
- PrintArr (select ($ testArr ));
- ?>
>>> Articles you may be interested in: php examples of practical and fast sorting algorithms PHP implementation of various sorting algorithms small example of php bubble sorting php simple example of bubble sorting PHP implementation of two-dimensional array sorting user-defined function php selection of sorting implementation code php bubble sorting implementation code php insert sorting implementation code php quick sort) function php for fast sorting function php for bubble sorting exchange sorting method php for bubble sorting (bubble sort) php bubble sorting algorithm example php bubble sorting and quick sorting example php two-dimensional array sorting method php multi-dimensional array sorting |