A php bubble sorting algorithm pen question

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.