Skip to content

Commit 211c28b

Browse files
committed
Add BubbleSort algorithm
1 parent 24f4090 commit 211c28b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.thealgorithms.sorting;
2+
3+
public class BubbleSort {
4+
public static void bubbleSort(int[] arr) {
5+
int n = arr.length;
6+
for (int i = 0; i < n - 1; i++) {
7+
for (int j = 0; j < n - i - 1; j++) {
8+
if (arr[j] > arr[j + 1]) {
9+
int temp = arr[j];
10+
arr[j] = arr[j + 1];
11+
arr[j + 1] = temp;
12+
}
13+
}
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)