-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbleSort.java
More file actions
34 lines (29 loc) · 891 Bytes
/
BubbleSort.java
File metadata and controls
34 lines (29 loc) · 891 Bytes
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
package main.code.array.sort;
public class BubbleSort {
public static void main(String[] args) {
int[] arr = {2, 4, 5, -9, 0, 5, 3, 12, 5};
for (int i = arr.length - 1; i > 0; i--) {
for (int j = 0; j < i; j++) {
if (arr[j] > arr[j + 1]) {
swap(j, j + 1, arr);
}
}
}
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
getRandom(99,1);
}
private static void swap(int i, int j, int[] arr) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
private static void getRandom(int min, int max){
int range = max - min + 1;
for (int i = 0; i <10 ; i++) {
int random =(int) (Math.random() * range) + min;
System.out.print(random + " ");
}
}
}