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 da9dcacCopy full SHA for da9dcac
2.selectionSort.md
@@ -22,18 +22,19 @@
22
```js
23
function selectionSort(arr) {
24
var len = arr.length;
25
- var minIndex, temp;
+ var minIndex;
26
for (var i = 0; i < len - 1; i++) {
27
minIndex = i;
28
for (var j = i + 1; j < len; j++) {
29
if (arr[j] < arr[minIndex]) { // 寻找最小的数
30
minIndex = j; // 将最小数的索引保存
31
}
32
33
- temp = arr[i];
34
- arr[i] = arr[minIndex];
35
- arr[minIndex] = temp;
36
- }
+ arr[i] = arr[i] ^ arr[minIndex];
+ arr[minIndex] = arr[i] ^ arr[minIndex];
+ // 或者使用ES6的解构赋值
37
+ }
38
return arr;
39
40
```
0 commit comments