-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathSelection_Sort.java
More file actions
39 lines (34 loc) · 1.04 KB
/
Selection_Sort.java
File metadata and controls
39 lines (34 loc) · 1.04 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
package Sorting;
import java.util.Scanner;
public class Selection_Sort {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter Length:- ");
int l=sc.nextInt();
int [] arr=new int[l];
for(int i=0;i<l;i++)
{
arr[i]=sc.nextInt();
}
int [] ans=Selection(arr);
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]+" ");
}
}
static int[] Selection(int[]arr)
{
for (int i = 0; i < arr.length-1; i++) {
int index=i;
for(int j=i+1;j<arr.length;j++)
{
if(arr[j]<arr[index])
{
int temp=arr[j];
arr[j]=arr[index];
arr[index]=temp;
}
}
}
return arr;
}
}