import java.util.*;
public class Sorts {
public static <T extends Comparable<T>> ArrayList<T> quickSort(ArrayList<T> list){
ArrayList<T> listaOrdenada;
listaOrdenada = new ArrayList<T>(list);
quickS(0, listaOrdenada.size()-1, listaOrdenada);
return listaOrdenada;
}
public static <T extends Comparable<T>> void quickS(int izq,int der,ArrayList<T> list){
int i = izq;
int j = der;
T pivote = list.get((izq+der)/2);
do{
while(list.get(i).compareTo(pivote) < 0) i++;
while(list.get(j).compareTo(pivote) > 0) j--;
if(i <= j){
T aux = list.get(i);
list.set(i, list.get(j));
list.set(j, aux);
i++;
j--;
}
}while(i <= j);
if( izq < j) quickS(izq, j, list);
if( i < der) quickS(i, der, list);
}
}
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.