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 6a86900

Browse files
bubble short implement
1 parent f2ed2a9 commit 6a86900

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

‎Shorting/bubbleShort.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@ class bubbleShort {
44
public static void main(String[] args) {
55
int[] arr = {20, 13, 10, 4, 2, 46, 8};
66
int size = arr.length;
7-
int temp = 0;
7+
int temp;
88

99
System.out.print("Before shorting: ");
1010
for (int num : arr) {
1111
System.out.print(num + " ");
1212
}
1313

14-
for (int i = 0; i <= size; i++) {
15-
for (int j = 0; j < size - 1; j++) {
14+
for (int i = 0; i < size; i++) {
15+
for (int j = 0; j < size - i - 1; j++) {
1616
if (arr[j] > arr[j + 1]) {
1717
temp = arr[j];
1818
arr[j] = arr[j + 1];
1919
arr[j + 1] = temp;
2020
}
2121
}
22+
System.out.println(" ");
23+
for (int num : arr) {
24+
System.out.print(num + " ");
25+
}
2226
}
2327
System.out.println(" ");
2428
System.out.print("After shorting: ");

0 commit comments

Comments
(0)

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