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 3bf8b02 commit 5f81fa2Copy full SHA for 5f81fa2
src/test/java/sort/BubbleSort.java
@@ -1,6 +1,7 @@
1
package sort;
2
3
import org.junit.Test;
4
+import utils.Utils;
5
6
import static org.hamcrest.CoreMatchers.is;
7
import static org.junit.Assert.assertThat;
@@ -14,13 +15,7 @@ public class BubbleSort {
14
15
16
@Test
17
public void test() {
- int[] arr = new int[5];
18
- arr[0] = 2;
19
- arr[1] = 1;
20
- arr[2] = 4;
21
- arr[3] = 0;
22
- arr[4] = 3;
23
-
+ int[] arr = {2,1,4,0,3};
24
int[] sortedArr = new int[arr.length];
25
for (int i = 0; i < sortedArr.length; i++) {
26
sortedArr[i] = i;
@@ -32,9 +27,7 @@ public int[] sort(int[] arr) {
32
27
for (int i = 0; i < arr.length - 1; i++) {
33
28
for (int j = i + 1; j < arr.length; j++) {
34
29
if (arr[i] > arr[j]) {
35
- int temp = arr[i];
36
- arr[i] = arr[j];
37
- arr[j] = temp;
30
+ Utils.swapValue(arr, i, j);
38
31
}
39
40
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments