Come devo comportarmi con lo spostamento dei nodi?
codice:
/*ALGORITMO DI ORDINAMENTO MERGESORT PER LE LISTE*/
static void mergesortL (Lista L)
{
mergesortL (L, 0, L.getSize()-1);
}
static void mergesortL (Lista L, int first, int last)
{
if (first < last)
{
int mid = (first + last) / 2;
mergesortL (L, first, mid);
mergesortL (L, mid+1, last);
mergeL (L, first, last);
}
}
static void mergeL (Lista L, int first, int last)
{
Lista temp = new Lista ();
int mid = (first + last) / 2;
int i1 = 0, i2 = first, i3 = mid + 1;
while (i2 <= mid && i3 <= last)
{
Nodo aux1=L.getNodo(i2), aux2=L.getNodo(i2), aux3=L.getNodo(i3);
if ( L.getNodo(i2).getInfo()>L.getNodo(i3).getInfo() )
{
temp.getNodo(i1).setNext( new Nodo (L.getNodo(i2).getInfo()) );
i1++;
i2++;
}
else
{
temp.getNodo(i1).setNext(new Nodo (L.getNodo(i3).getInfo()));
i1++;
i3++;
}
}
while (i2 <= mid)
{
temp.getNodo(i1).setNext( new Nodo (L.getNodo(i2).getInfo()) );
i1++;
i2++;
}
while (i3 <= last)
{
temp.getNodo(i1).setNext(new Nodo (L.getNodo(i3).getInfo()));
i1++;
i3++;
}
//for (i1 = 0, i2 = first; i2 <= last; array[i2++] = temp[i1++]);
}