A PHP pen Question: use a pseudo-language combined with the data structure bubble sort method to sort the following data sets by 1023614102523859945. Everyone should be very familiar with the bubble sorting, and I will not talk about the principle. here we only make simple records. The following is the reference code.
A PHP pen Question: use a pseudo-language combined with the data structure bubble sort method to sort the following groups of data 10 2 36 14 10 25 23 85 99 45.
Everyone should be very familiar with the bubble sorting, and I will not talk about the principle. here we only make simple records. The following is the reference code.
Array ('fid' => 1, 'tid' => 1, 'name' => 'name1'), '1' => array ('fid' => 1, 'tid' => 2, 'name' => 'name2'), '2' => array ('fid' => 1, 'tid' => 5, 'name' => 'name3'), '3' => array ('fid' => 1, 'tid' => 7, 'name' => 'name4'), '4' => array ('fid' => 3, 'tid' => 9, 'name' => 'name5'); $ arr2 = array (); foreach ($ arr1 as $ key => $ value) {$ arr2 [$ value ['fid'] [] = array ('tid' => $ value ['tid'], 'Name '=> $ Value ['name']);} return $ arr2;} // print_r ($ arr2); // $ eString = 'Open _ door '; public function getString ($ eString = null) {$ eString = explode ('_', $ eString); $ eString = array_map ("ucfirst", $ eString ); $ eString = implode ($ eString, ''); return $ eString;}/*** bubble sort * @ return unknown */public function getBubble () {$ isOver = false; $ bubbleArray = array (,); $ bubbleResul T = $ bubbleArray; do {$ bubbleArray = $ bubbleResult; $ isOver = true; foreach ($ bubbleArray as $ key => $ value) {if ($ value <$ bubbleResult [$ key-1]) {$ bubbleResult [$ key] = $ bubbleResult [$ key-1]; $ bubbleResult [$ key-1] = $ value; $ isOver = false ;}} while (! $ IsOver); return $ bubbleResult; }}$ engage = new engage (); echo'';print_r($engage->getArray());echo '
'; Echo $ engage-> getString ('Make _ by_nowamagic'); echo'';print_r($engage->getBubble());echo '
';?>
The program running result is as follows:
Array( [1] => Array ( [0] => Array ( [tid] => 1 [name] => Name1 ) [1] => Array ( [tid] => 2 [name] => Name2 ) [2] => Array ( [tid] => 5 [name] => Name3 ) [3] => Array ( [tid] => 7 [name] => Name4 ) ) [3] => Array ( [0] => Array ( [tid] => 9 [name] => Name5 ) ))MakeByNowamagicArray( [0] => 2 [1] => 10 [2] => 10 [3] => 14 [4] => 23 [5] => 25 [6] => 36 [7] => 45 [8] => 85 [9] => 99)
This article is available at http://www.nowamagic.net/librarys/veda/detail/1559.