Php basic sorting
[PHP] code
$ Arr [$ I]) {$ temp = $ arr [$ i-1]; $ arr [$ i-1] = $ arr [$ I]; $ arr [$ I] = $ temp; $ swapped = true ;}}while ($ swapped); return $ arr ;}// select the sort function selectSort ($ arr) {$ minimumPosition = 0; $ len = count ($ arr); for ($ I = 0; $ I <$ len-1; $ I ++) {for ($ j = $ I + 1; $ j <$ len-$ I; $ j ++) {if ($ arr [$ j] <$ arr [$ minimumPosition]) {$ minimumPosition = $ j ;}$ temp = $ arr [$ I]; $ arr [$ I] = $ arr [$ minimumPosition]; $ arr [$ minimumPosition] = $ temp;} return $ arr;} // Insert the sorting function insertSort1 ($ arr) {$ len = count ($ arr); for ($ I = 1; $ I <$ len; $ I ++) {$ extractElement = $ arr [$ I]; for ($ j = $ I-1; $ j> = 0; $ j --) {if ($ arr [$ j]> $ extractElement) {$ arr [$ j + 1] = $ arr [$ j]; $ arr [$ j] = $ extractElement ;}} return $ arr ;} /*** insert sort ** @ param Array $ a unordered set * @ return Array ordered set */function insertSort2 ($ a) {$ temp; $ I; $ j; $ size_a = count ($ a); # for ($ I = 1; $ I <$ size_a; $ I ++) starting from the second element) {if ($ a [$ I] <$ a [$ i-1]) {$ j = $ I; # save the location of the current element $ temp = $ a [$ I]; # value of the current element # Move the element to the right if it is smaller than itself, otherwise insert the element to the current position while ($ j> 0 & $ temp <$ a [$ j-1]) {$ a [$ j] = $ a [$ j-1]; $ j --;} # insert element $ a [$ j] = $ temp;} return $ ;} /*** obtain the random number * @ param Integer $ size quantity * @ return Integer */function randomNumber ($ size = 10) {$ rand = array (); srand (time (NULL); for ($ I = 0; $ I <$ size; $ I ++) {array_push ($ rand, mt_rand ));} return $ rand;} // print_r (implode (",", bubbleSort ($ unsortList); // print_r (implode (",", selectSort ($ unsortList); // print_r (implode (",", insertSort1 ($ unsortList); // print_r (implode (",", insertSort2 ($ unsortList )));