PHP sorting problems

Source: Internet
Author: User
The conclusion of the TCP/IP exam in the last section of the PHP sorting question has ended my sophomore life. In the morning, let's see if our friends are still asleep and don't know what to do. then they began to wander. When I saw a brother sort the arrays in PHP using the bubble sorting algorithm, I was surprised ?? Why are so many sorting functions in PHP still writing this ?! Later I thought about it. I was wrong. programming is not just a mechanical movement, but a set of multiple ways of thinking. the purpose of practicing algorithms is to expand my own thinking.

I also tried to write ......

                  

$ Array [$ I]) {// Here, the value of the exchanged array $ temp = $ array [$ I]; $ array [$ I] = $ array [$ j]; $ array [$ j] = $ temp ;}} print_r ($ array);?>

This is the bubble sorting algorithm, and the result is still acceptable:

                  

---------- PHP Debug ---------- Array ([0] => 86 [1] => 56 [2] => 41 [3] => 36 [4] => 15 [5] => 10 [6] => 9 [7] => 8 [8] => 5 [9] => 4 [10] => 3 [11] => 2) output completed (0 seconds)-normal termination

With the little joy of success, I wrote another one, and the problem came out ??

                  

$ Array [$ I]) {// Here is the exchanged key value $ temp = $ I; $ I = $ j; $ j = $ temp ;}}} print_r ($ array);?>

The results are terrible ......

                  

---------- PHP Debug ---------- Array ([0] => 10 [1] => 5 [2] => 36 [3] => 86 [4] => 2 [5] => 56 [6] => 9 [7] => 15 [8] => 8 [9] => 4 [10] => 3 [11] => 41) output completed (0 seconds)-normal termination

I didn't change either. Why ?? Why ???

I forgot to give my opinion when I pass ......

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.