forked from dharmanshu1921/Java
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelection_Sort.java
More file actions
Latest commit
32 lines (26 loc) · 676 Bytes
/
Copy pathSelection_Sort.java
File metadata and controls
32 lines (26 loc) · 676 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
packagelec_12;
importjava.util.Arrays;
publicclassSelection_Sort {
publicstaticvoidmain(String[] args) {
int[] arr = { 50, 40, 30, 20, 10 };
selection(arr);
}
publicstaticvoidselection(int[] arr) {
intlast = arr.length - 1;
while (last > 0) {
intmax_idx = 0;
for (inti = 0; i <= last; i++) {
if (arr[i] > arr[max_idx]) {
max_idx = i;
}
}
System.out.println(max_idx + " Swapping " + last);
inttemp = arr[max_idx];
arr[max_idx] = arr[last];
arr[last] = temp;
last--;
System.out.println(Arrays.toString(arr));
System.out.println("******************************");
}
}
}