We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6954cf8 commit 19a929aCopy full SHA for 19a929a
1.bubbleSort.md
@@ -109,4 +109,28 @@ public class BubbleSort implements IArraySort {
109
return arr;
110
}
111
112
+```
113
+
114
+## 9. PHP 代码实现
115
116
+```php
117
+function bubbleSort($arr)
118
+{
119
+ $count = count($arr);
120
+ if ($count == 0) return false;
121
+ // 设置一个空数组 用来接收冒出来的泡
122
+ $tmp = [];
123
+ // 该层循环控制 需要冒泡的轮数
124
+ for ($i = 0; $i < $count; $i++) {
125
+ //该层循环用来控制每轮 冒出一个数需要比较的次数
126
+ for ($j = 0; $j < $count - 1 - $i; $j++) {
127
+ if ($arr[$j] > $arr[$j + 1]) {
128
+ $tmp = $arr[$j];
129
+ $arr[$j] = $arr[$j + 1];
130
+ $arr[$j + 1] = $tmp;
131
+ }
132
133
134
+ return $arr;
135
+}
136
```
0 commit comments