package org.lion.euler.study.sort; /** * selection sort * <pre> * Principle: Select the smallest element in the remaining array each time, and exchange it with the first one of the remaining elements * </pre> * @author lion * */ public class SelectSort extends AbstractSort { @Override public void sort(Integer[] array) { for (int i = 0; i < array.length; i++) { int min = i; for (int j = i + 1; j < array.length; j++) { if(array[min] > array[j]){ min = j; } } if(min != i){ swap(array, i, min); } } } }
Sorting - JAVA implementation [eight] selection sorting
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325981034&siteId=291194637
Recommended
Ranking