forked from onlybooks/java-algorithm-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbleSortExample.java
More file actions
23 lines (20 loc) · 596 Bytes
/
BubbleSortExample.java
File metadata and controls
23 lines (20 loc) · 596 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package ch17;
import java.util.Arrays;
public class BubbleSortExample {
static int[] Bubblesort(int[] A) {
for (int i = 1; i < A.length; i++) {
for (int j = 0; j < A.length - 1; j++) {
if (A[j] > A[j + 1]) {
int temp = A[j];
A[j] = A[j + 1];
A[j + 1] = temp;
}
}
}
return A;
}
public static void main(String[] args) {
int[] A = new int[]{38, 27, 43, 3, 9, 82, 10};
System.out.println(Arrays.toString(Bubblesort(A)));
}
}