PHP quick sorting algorithm (non-recursive) to implement php code
0) {if ($ I> 30) {$ test [] = mt_rand ($ I-30, $ I --);} else {$ test [] = mt_rand (1, $ I --) ;}// shuffle ($ test); echo count ($ test), "\ n"; // sort ($ test); echo implode (", ", $ test)," \ n "; $ t1 = microtime (true); quicksort ($ test); echo implode (", ", $ test ), "\ n"; echo microtime (true)-$ t1 ,"
\ N "; function quicksort (array & $ sort) {$ end = count ($ sort); if (-- $ end <1) {return ;}$ beg = 0; $ stack = array (); while (true) {$ I = $ beg; $ l = $ end; $ o = $ sort [$ x = mt_rand ($ I, $ l)]; while ($ I <$ l) {// if ($ sort [$ I]> $ o) {while ($ I <$ l) {// if ($ sort [$ l] <= $ o) {$ tmp = $ sort [$ I]; $ sort [$ I] = $ sort [$ l]; $ sort [$ l] = $ tmp; $ I ++; $ l --; continue 2 ;} $ l --;} goto re;} $ I ++;} if ($ sort [$ I] <$ o) {$ sort [$ x] = $ sort [$ I]; $ sort [$ I] = $ o;} // echo $ I, ",", $ l, ";", $ beg, ",", $ end, "\ n"; re: // save if ($ I <$ end) on the right) {$ stack [] = $ I; $ stack [] = $ end;} if (-- $ I >$ beg) {$ end = $ I; // Continue to the left} elseif ($ stack) {// return to continue to the right $ end = array_pop ($ stack); $ beg = array_pop ($ stack );} else {break ;}}}