* ** @ Title Bubble Sorting * @ desc in the number of groups to be sorted, all the numbers within the range not sorted yet, * compare and adjust the adjacent two numbers from top to bottom, so that a large number will sink and a small number will go up. * That is, when the numbers of two adjacent parties are compared and their sorting and sorting requirements are the opposite, they are exchanged. * @ P
/*** @ Title Bubble Sorting * @ desc in the number of groups to be sorted, all the numbers in the range not sorted yet, * compare and adjust the adjacent two numbers from top to bottom, so that a large number will sink and a small number will go up. * That is, when the numbers of two adjacent parties are compared and their sorting and sorting requirements are the opposite, they are exchanged. * @ P
/*** @ Title Bubble Sorting * @ desc in the number of groups to be sorted, all the numbers in the range not sorted yet, * compare and adjust the adjacent two numbers from top to bottom, so that a large number will sink and a small number will go up. * That is, when the numbers of two adjacent parties are compared and their sorting and sorting requirements are the opposite, they are exchanged. * @ Param array $ data * @ return array $ data * @ author bandit */function bubble_sort (array $ data) {$ length = count ($ data ); for ($ I = $ length; $ I> 1; $ I --) {for ($ j = 0; $ j <$ I-1; $ j ++) {if ($ data [$ j]> $ data [$ I + 1]) {list ($ data [$ I], $ data [$ j]) = array ($ data [$ j], $ data [$ j + 1]) ;}}return $ data ;} /*** @ ttile quick sorting * @ desc * @ param array $ data ** @ return array $ data * @ author bandit */function quick_sort ($ data) {$ front = $ end = array (); $ length = count ($ data); if ($ length <= 1) {return $ data ;} for ($ I = 1; $ I <$ length; $ I ++) {if ($ data [$ I] <= $ data [0]) {$ front [] = $ data [$ I]; unset ($ data [$ I]);} else {array_unshift ($ end, $ data [$ I]); unset ($ data [$ I]); }}$ front = quick_sort ($ front); $ end = quick_sort ($ end); return array_merge ($ front, array ($ data [0]), $ end );}
Summary of the stability, time complexity, and space complexity of various sorting:
Increase of time complexity function O (n)
Reference: http://blog.csdn.net/hguisu/article/details/7776068
Original article address: Sorting Algorithm PHP implementation [below]. Thanks to the original author for sharing.