forked from Ishaan28malik/Hacktoberfest-2024
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionSort.java
More file actions
33 lines (22 loc) · 837 Bytes
/
SelectionSort.java
File metadata and controls
33 lines (22 loc) · 837 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
package arrays;
public class SelectionSort {
public static void main(String[] args) {
// TODO Auto-generated method stub
int a[] = {-4, -5, 9, 7, 10, 6};
int n = a.length;
for(int i = 0; i<n-1; i++) {
int minInd = i;
for(int j = i; j<n; j++) {
if(a[j] < a[minInd]) {
minInd = j;
}
}
int temp = a[i];
a[i] = a[minInd];
a[minInd] = temp;
}
for(int e : a) {
System.out.print(e + " ");
}
}
}