-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelection.java
More file actions
32 lines (28 loc) · 856 Bytes
/
Copy pathSelection.java
File metadata and controls
32 lines (28 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class Selection {
public static void main(String[] args) {
int arr[] = { 6, 5, 2, 8, 9, 4 };
int size = arr.length;
int min = -1;
int temp = 0;
for (int i = 0; i < size - 1; i++) {
min = i;
for (int j = i + 1; j < size; j++) {
if (arr[min] > arr[j]) {
min = j;
}
}
// System.out.println();
// for (int k = 0; k < size; k++) {
// System.out.print(arr[k] + " ");
// }
// System.out.println();
temp = arr[min];
arr[min] = arr[i];
arr[i] = temp;
}
for (int k = 0; k < size; k++) {
System.out.print(arr[k] + " ");
}
System.out.println();
}
}