A school teacher decides to write a program to store class records and marks. Part of this program involves using a sort algorithm. The algorithm shown is a selection sort and to test it, the teacher has set up an array VALUES[] with 5 elements of test data.
Answers
Answered by
0
Answer:
import java.util.*;
class selectionSort
{
static void selectionSort(int[] arr)
{
for(int i = 0; i < arr.length - 1; i++)
{
int min = i;
for(int j = i + 1; j < arr.length; j++)
{
if(arr[min] > arr[j])
{
min = j;
}
}
int temp = arr[i];
arr[i] = arr[min];
arr[min] = temp;
}
}
public static void main(String[] args)
{
int[] arr = {6,8,3,9,1,4,5,2};
selectionSort(arr);
System.out.println(Arrays.toString(arr));
}
}
Explanation:
Similar questions