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 ......