This part of the algorithm has the function of interleaving the elements of a List<Integer>
(list of normal integers) using the Mergesort sort algorithm. ERROR ON LINE 7
private static List intercalar(List<Integer> list, int l, int h, int r){
int i = l, j = h, /*marcador do topo*/t = 0;
List<Integer> topo = Arrays.asList();
while(i < h && j < r){ // O(n/2) =
if(list.get(i) < list.get(j)){
topo.add(t, list.get(i)); **ERRO AQUI**
i++;
} else {
topo.add(t, list.get(j));
j++;
}
t++;
}
//anexa o restante das cartas(as cartas q ficaram sozinhas)
while(i < h){
topo.add(t, list.get(i));
t++;
i++;
}
while(j < r){
topo.add(t, list.get(j));
t++;
j++;
}
for(i = l, t = 0 ; i < r ; i++, t++) {
list.set(i, topo.get(t));
}
return list;
}
Displays the following error:
java.util.UnsupportedOperationException: null (in java.util.AbstractList)