-
Notifications
You must be signed in to change notification settings - Fork 0
/
SelectionSortExample.java
40 lines (35 loc) · 1.04 KB
/
SelectionSortExample.java
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
import java.util.Scanner;
public class SelectionSortExample2
{
public static void main(String args[])
{
int size, i, j, temp;
int arr[] = new int[50];
Scanner scan = new Scanner(System.in);
System.out.print("Enter Array Size : ");
size = scan.nextInt();
System.out.print("Enter Array Elements : ");
for(i=0; i<size; i++)
{
arr[i] = scan.nextInt();
}
System.out.print("Sorting Array using Selection Sort Technique..\n");
for(i=0; i<size; i++)
{
for(j=i+1; j<size; j++)
{
if(arr[i] > arr[j])
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
System.out.print("Now the Array after Sorting is :\n");
for(i=0; i<size; i++)
{
System.out.print(arr[i]+ " ");
}
}
}