File tree Expand file tree Collapse file tree 1 file changed +3
-10
lines changed
Expand file tree Collapse file tree 1 file changed +3
-10
lines changed Original file line number Diff line number Diff line change 11package sort ;
22
33import org .junit .Test ;
4+ import utils .Utils ;
45
56import static org .hamcrest .CoreMatchers .is ;
67import static org .junit .Assert .assertThat ;
@@ -14,13 +15,7 @@ public class BubbleSort {
1415
1516 @ Test
1617 public void test () {
17- 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-
18+ int [] arr = {2 ,1 ,4 ,0 ,3 };
2419 int [] sortedArr = new int [arr .length ];
2520 for (int i = 0 ; i < sortedArr .length ; i ++) {
2621 sortedArr [i ] = i ;
@@ -32,9 +27,7 @@ public int[] sort(int[] arr) {
3227 for (int i = 0 ; i < arr .length - 1 ; i ++) {
3328 for (int j = i + 1 ; j < arr .length ; j ++) {
3429 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 );
3831 }
3932 }
4033 }
You can’t perform that action at this time.
0 commit comments