Ciao ragazzi, non capisco perchè mi va in Exception quando richiamo ricorsivamente la funzione mergeSort per ordinare stringhe di testo in ordine lessicografico crescente. Qualche suggerimento?
Ecco il codice:
codice:public class OrdinaTesto { /* Variabili */ public static String matricola = "800326"; /* Costruttore */ public OrdinaTesto() {} /* Metodi */ public static void ordinaCrescente(String testo[]) { int inf = 0; int sup = testo.length; if (sup < 2) return; mergeSort(testo, inf, sup); } public static void mergeSort(String testo[], int inf, int sup) { int m = (inf+sup)/2; if (sup < 2) return; mergeSort(testo, inf, m); mergeSort(testo, m+1, sup); merge(testo, inf, m, sup); } public static void merge(String testo[], int inf, int med, int sup) { String testoAux[] = new String[sup-inf+1]; int i = 0; int i1 = inf; int i2 = med; while(i1 < med && i2 < sup) { if(testo[i1].compareTo(testo[i2]) <= 0) testoAux[i++] = testo[i1++]; else testoAux[i++] = testo[i2++]; } while(i1 < med) testoAux[i++] = testo[i1++]; while(i2 < sup) testoAux[i++] = testo[i2++]; while(i2 > inf) testo[--i2] = testoAux[--i]; } }

Rispondi quotando
