public class demo1
{
public static void selectionSort(int[] arr)
{
for (int a = 0; a < arr.length - 1; a++)
{
int res = a;
for (int b = a + 1; b < arr.length; b++)
{
if (arr[b] < arr[res])
{
res = b;
}
}
int smallerNumber = arr[res];
arr[res] = arr[a];
arr[a] = smallerNumber;
}
}
public static void main(String array[]){
int[] array1 = {8,43,2,143,6,75,24};
System.out.println("Before Selection Sort");
for(int a:array1)
{
System.out.print(a+" ");
}
System.out.println();
selectionSort(array1);
System.out.println("After Selection Sort");
for(int a:array1)
{
System.out.print(a+" ");
}
}
} Java
Program to implement Selection Sorting.

Written by
View ProfileNikhil Juneja
Passionate software developer and technical contributor at TutorialsLink.
