Skip to content

Commit 064ca1c

Browse files
authored
Merge pull request #109 from SRINIDHI-G/patch-7
Create bubble_sort
2 parents ff2dc96 + 0a1f066 commit 064ca1c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

java/solution/bubble_sort

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
public void bubbleSort(int[] arr) {
2+
3+
int n = arr.length;
4+
5+
for (int i = 0; i < n – 1; i++) {
6+
7+
for (int j = 0; j < n – i – 1; j++) {
8+
9+
if (arr[j] > arr[j + 1]) {
10+
11+
// Swap arr[j] and arr[j+1]
12+
13+
int temp = arr[j];
14+
15+
arr[j] = arr[j + 1];
16+
17+
arr[j + 1] = temp;
18+
19+
}
20+
21+
}
22+
23+
}
24+
25+
}

0 commit comments

Comments
 (0)