-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathselection_sort.java
More file actions
37 lines (28 loc) · 902 Bytes
/
selection_sort.java
File metadata and controls
37 lines (28 loc) · 902 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
34
35
36
37
import java.util.Scanner;
public class selection_sort{
public static void main(String[] args){
Scanner sc= new Scanner(System.in);
System.out.println("enter the size of array");
int n = sc.nextInt();
int a[] = new int[n];
System.out.println("enter the array");
for(int i=0; i<n; i++){
a[i]=sc.nextInt();
}
for(int i=0; i<n-1; i++){
int minimun = i;
for(int j=i; j<n; j++){
if(a[j]<a[minimun]){
minimun = j;
}
}
int temp = a[i];
a[i] = a[minimun];
a[minimun] = temp;
}
System.out.println("Sorted array");
for(int e:a){
System.out.print(e+" ");
}
}
}