Shell Sort (Generic)

import java.util.*; public class Sorts { public static <T extends Comparable<T>> ArrayList<T> shellSort(ArrayList<T> list){ ArrayList<T> listaOrdenada; listaOrdenada = new ArrayList<T>(list); int intervalo = listaOrdenada.size()/2; while(intervalo >= 1){ for(int i = 0; i < intervalo; i++){ for(int j = intervalo+i; j < listaOrdenada.size(); j+=intervalo){ T aux = listaOrdenada.get(j); int k = j - intervalo; while(k >= 0 && listaOrdenada.get(k).compareTo(aux) > 0){ listaOrdenada.set(k +intervalo, listaOrdenada.get(k)); k-=intervalo; } listaOrdenada.set(k + intervalo, aux); } } intervalo /= 2; } 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.