Untitled
unknown
java
3 years ago
1.2 kB
7
Indexable
import java.util.*;
public class LabOneQuestionTwo
{
public static void main(String[] args)
{
int[] randomNumsList = new int[100000];
Random random = new Random();
for(int i = 0; i < randomNumsList.length; i++) {
randomNumsList[i] = random.nextInt(100000);
}
StopWatch stopWatch = new StopWatch();
selectionSort(randomNumsList);
stopWatch.stop();
System.out.printf("The sort time is %d " ,+ stopWatch.getElapsedTime());
}
public static void selectionSort(int[] randomNumsList) {
for (int i = 0; i < randomNumsList.length; i++) {
int currentMin = randomNumsList[i];
int currentMinIndex = i;
for (int j = i + 1; j < randomNumsList.length; j++) {
if (currentMin > randomNumsList[j]) {
currentMin = randomNumsList[j];
currentMinIndex = j;
}
}
if (currentMinIndex != i) {
randomNumsList[currentMinIndex] = randomNumsList[i];
randomNumsList[i] = currentMin;
}
}
}
}Editor is loading...