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 b1bdba8

Browse files
selectionshort implement
1 parent 6a86900 commit b1bdba8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

‎Shorting/selectionShort.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
public class selectionShort {
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;
8+
9+
System.out.print("Before shorting: ");
10+
for (int num : arr) {
11+
System.out.print(num + " ");
12+
}
13+
// Selection short
14+
for (int i = 0; i < size-1; i++) {
15+
int smallest = i;
16+
for (int j = i + 1; j < size; j++) {
17+
if (arr[j] < arr[smallest]) {
18+
smallest = j;
19+
}
20+
}
21+
temp = arr[smallest];
22+
arr[smallest] = arr[i];
23+
arr[i] = temp;
24+
}
25+
26+
System.out.println(" ");
27+
System.out.print("After shorting: ");
28+
for (int num : arr) {
29+
System.out.print(num + " ");
30+
}
31+
}
32+
}

0 commit comments

Comments
(0)

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