import java.util.*;
public class Sorts {
public static <T extends Comparable<T>> ArrayList<T> selectionSort(ArrayList<T> list){
ArrayList<T> listaOrdenada;
listaOrdenada = new ArrayList<T>(list);
for(int x = 0; x < listaOrdenada.size() - 1; x++){
T menor = listaOrdenada.get(x);
int pos = x;
for(int y = x + 1; y < listaOrdenada.size(); y++){
if(listaOrdenada.get(y).compareTo(menor) < 0){
menor = listaOrdenada.get(y);
pos = y;
}
}
listaOrdenada.set(pos, listaOrdenada.get(x));
listaOrdenada.set(x, menor);
}
return listaOrdenada;
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.