-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbleSortApp2.java
More file actions
54 lines (46 loc) · 1.39 KB
/
BubbleSortApp2.java
File metadata and controls
54 lines (46 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
class MyBubbleSort2 {
private List<Integer> list = new ArrayList<>(Arrays.asList(4, 2, 9, 3, 1, 3, 11, 8));
private int[] array = {4, 2, 9, 3, 1, 3, 11, 8};
int[] sort(int[] array) {
int min;
for (int i = 0; i < array.length; i++) {
for (int j = i + 1; j < array.length; j++) {
if(array[i] > array[j]){
min = array[j];
array[j] = array[i];
array[i] = min;
}
}
}
return array;
}
List<Integer> sort(List<Integer> array) {
int min;
for (int i = 0; i < array.size(); i++) {
for (int j = i + 1; j < array.size(); j++) {
if (array.get(i) > array.get(j)) {
min = array.get(j);
array.set(j, array.get(i));
array.set(i, min);
}
}
}
return array;
}
public List<Integer> getList() {
return list;
}
public int[] getArray() {
return array;
}
}
public class BubbleSortApp2 {
public static void main(String[] args) {
MyBubbleSort2 bubbleSort = new MyBubbleSort2();
bubbleSort.sort(bubbleSort.getArray());
System.out.println(Arrays.toString(bubbleSort.getArray()));
}
}