3
I’m having a problem here at this meeting. These are functions for an array of objects using the Quick Sort algorithm, and I’m getting the Stackoverflow error, and I can’t identify the source. Someone help me identify the source of the error?
static Musica[] ordenarMusicosIdQuickSort(Musica[] musica){
return ordenarMusicosIDQuickSort(musica, 0, musica.length);
}
static Musica[] ordenarMusicosIDQuickSort(Musica[] musica, int left, int right){
if(left<right){
int posicaoPivot = partition(musica, left, right-1);
musica = ordenarMusicosIDQuickSort(musica, left, right);
musica = ordenarMusicosIDQuickSort(musica, posicaoPivot + 1, right);
}
return musica;
}
static int partitionID(Musica[] musica, int left, int right){
Musica pivot=musica[right];
int startR=left-1;
for(int endR=left; endR<right; endR++){
if(musica[endR].id_interprete>pivot.id_interprete){
startR++;
Musica temp=musica[endR];
musica[endR]=musica[startR];
musica[startR]=temp;
}
}
Musica temp=musica[right];
musica[right]=musica[startR+1];
musica[startR+1]=temp;
return startR+1;
}
}
Stack overflow reminds infinite recursion. Your recursive condition may be in trouble
– Jefferson Quesado
Yes, your recursion has a problem
– Jefferson Quesado
A Stack overflow problem in Stack overflow! It’s right in the right place!
– Isac