forked from nishitpanchal395/projecthactoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionSort.java
More file actions
33 lines (26 loc) · 721 Bytes
/
SelectionSort.java
File metadata and controls
33 lines (26 loc) · 721 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
33
// import java.sql.Array;
import java.util.Arrays;
class SelectionSort {
public static void main(String[] args) {
int[] arr = { 11, 2, 66, 77, 30 };
int n = arr.length;
SelSort(arr, n);
System.out.println(Arrays.toString(arr));
}
private static void SelSort(int[] arr, int n) {
int min, temp;
for (int k = 0; k < n - 1; k++) {
min = k;
for (int j = k + 1; j < n; j++) {
if (arr[j] < arr[min]) {
min = j;
}
}
if (min != k) {
temp = arr[k];
arr[k] = arr[min];
arr[min] = temp;
}
}
}
}