-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselectsort.java
More file actions
46 lines (36 loc) · 1.18 KB
/
selectsort.java
File metadata and controls
46 lines (36 loc) · 1.18 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.Scanner;
public class selectsort {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s= new Scanner(System.in);
int i, j, swap,n;
System.out.println("Enter the number of elements");
n= s.nextInt();
int a[]= new int[n];
System.out.println("Enter the number to be sorted");
for(i=0;i<n;i++)
{
a[i]= s.nextInt();
}
// SELECT SORT
for(i=0;i<n;i++)
{
int minimumnumberindex=i;
for(j=i+1;j<n;j++)
{
if(a[minimumnumberindex]>a[j])
{
minimumnumberindex=j;
}
}
swap= a[i];
a[i]=a[minimumnumberindex];
a[minimumnumberindex]= swap;
}
System.out.println("Sorted List:");
for(i=0;i<n;i++)
{
System.out.println("Numbers are:" +a[i]);
}
}
}