Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f2ed2a9

Browse files
bubble short implement easyway
1 parent 2aea536 commit f2ed2a9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

‎Shorting/bubbleShort.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
class bubbleShort {
3+
4+
public static void main(String[] args) {
5+
int[] arr = {20, 13, 10, 4, 2, 46, 8};
6+
int size = arr.length;
7+
int temp = 0;
8+
9+
System.out.print("Before shorting: ");
10+
for (int num : arr) {
11+
System.out.print(num + " ");
12+
}
13+
14+
for (int i = 0; i <= size; i++) {
15+
for (int j = 0; j < size - 1; j++) {
16+
if (arr[j] > arr[j + 1]) {
17+
temp = arr[j];
18+
arr[j] = arr[j + 1];
19+
arr[j + 1] = temp;
20+
}
21+
}
22+
}
23+
System.out.println(" ");
24+
System.out.print("After shorting: ");
25+
for (int num : arr) {
26+
System.out.print(num + " ");
27+
}
28+
29+
}
30+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /