| For more information about bubble sorting implemented by php code, see.
Bubble sorting(BubbleSort) compares two adjacent numbers, placing decimals in front, and placing large numbers in the back. That is, in the first step: first compare the number of 1st and the number of 2nd, and put the decimal number before and after the large number. Then compare the numbers of 2nd and 3rd, place the decimal places before and after the large number, and continue until the last two digits are compared. Place the decimal places before and after the large number. So far, the first stop is over, and the maximum number is placed at the end. In the second round: The comparison starts from the first logarithm (because the number of 2nd is exchanged with the number of 3rd, the number of 1st is no less than 2nd). before and after placing the decimal number, always compare to the second to the last (the largest position in the last), and the second stop, get a new maximum number at the penultimate position (in fact, it is the second largest number in the entire series ). In this case, repeat the above process until the sorting is completed. If you are interested, you can refer to the example of php bubble sorting introduced by the programmer's house.
Sample code:
$ Arr [$ j + 1]) {// if the number above is greater than the number next to it, they will switch $ temp = $ arr [$ j]; $ arr [$ j] = $ arr [$ j + 1]; $ arr [$ j + 1] = $ temp ;}}$ arr = array (, 99,, 5,-,-7); bubbleSort ($ arr); print_r ($ arr); // The array is a value transfer, so an & symbol is added during the transfer, change the external variable // bbs.it-home.org?> |