Insert sort (Insertion sort): Inserts a record to be sorted each time, pressing its keyword size into the appropriate location in the previously sorted sub-file until all records are inserted.
Insert sort (one-dimensional array) function Insert_sort ($arr) {$count = count ($arr), for ($i =1; $i < $count; $i + +) {$tmp = $arr [$i]; $j = $i -1;whi Le ($arr [$j] > $tmp) {$arr [$i] = $arr [$j]; $arr [$j] = $tmp; $j--;}} return $arr;}
Select sort (Selection sort): Each time a record of the smallest keyword is selected from the record to be sorted, the order is placed at the end of the ordered sub-file until all records have been sorted.
Select sort (one-dimensional array) function Selection_sort ($arr) {$count = count ($arr), for ($i =0; $i < $count; $i + +) {$k = $i; for ($j = $i +1; $j < $count; $j + +) {if ($arr [$k] > $arr [$j]) {$k = $j;} if ($k! = $i) {$tmp = $arr [$i]; $arr [$i] = $arr [$k]; $arr [$k] = $tmp;}}} return $arr;}
Bubble sort (Bubble sort): 22 Compare the keywords of the records to be sorted, and find that the two records are exchanged in reverse order until there is no reverse record position.
Bubble sort (one-dimensional array)//The actual effect is that each loop places the smallest value in the array into the first segment of the array, and then the next loop no longer loops the key where the correct array value is placed, and so on function Selection_sort ($arr) {$count = Count ($arr); if ($count <= 0) return false;for ($i =0; $i < $count; $i + +) {for ($j = $count-1; $j > $i; $j-) {if ($arr [$j] < $ array[$j-1]) {$tmp = $arr [$j]; $arr [$j] = $arr [$j-1]; $arr [$j-1] = $tmp;}}} return $arr;}
Quick sort: Essentially the same as bubbling sort, is an application that belongs to an interchange sort.
Quick sort (one-dimensional array) function Quick_sort ($arr) {$count = count ($arr), if ($count <= 1) return $arr; $key = $arr [0]; $left _arr = Array (); $right _arr = Array (); for ($i =1; $i < $count; $i + +) {if ($arr [$i] <= $key) $left _arr[] = $arr [$i];else$right_ arr[] = $arr [$i];} $left _arr = Quick_sort ($left _arr); $right _arr = Quick_sort ($right _arr); return Array_merge ($left _arr,array ($arr), $ Right_arr);}
The above describes the PHP implementation of the common sorting algorithm, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.