-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionSort.java
More file actions
32 lines (29 loc) · 994 Bytes
/
SelectionSort.java
File metadata and controls
32 lines (29 loc) · 994 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
package yayyy;
import java.util.*;
public class SelectionSort {
public static void selectionsort(int[] input) {
for(int i=0;i<input.length-1;i++)//for no.of rounds {
{
int min=input[i];
int minIndex=i;
for(int j=i+1;j<input.length;j++) {
if(input[j]<min) {
min=input[j];
minIndex=j;
}
}
//now swap
if(minIndex !=i) {
input [minIndex]=input[i];
input[i]=min;
}
}
}
public static void main(String [] args) {
int input[]= {2,6,9,1,5};
selectionsort(input);
for(int i=0;i<input.length;i++) {
System.out.println(input[i]+" ");
}
}
}