So I am trying to make a mergesort program in java (specifically processing) that steps through the process frame by frame. When it sorted it in 1 frame by going through for loops it seemed to work fine (I didn't test it extensively as it wasn't my goal) but after making the changes to it necessary to have it function, it doesn't seem to want to work correctly.
I haven't tried a whole lot as I have absolutely no idea what could be causing this.
merge();
if (i1 < arr.length) {
if (i2 < arr.length) {
if (i3 <= i2 + i1) {
i3++;
} else {
i2 += i1 * 2;
l = i2 + 0;
r = i2 + i1;
}
} else {
i1 *= 2;
i2 = 0;
i3 = 0;
l = 0;
r = i1 + 0;
arr = w.clone();
}
} else {
noLoop();
}
void merge() {
int lMax = i2 + i1;
int rMax = i2 + i1 * 2;
if (r < arr.length - 1 && l < arr.length - 1) {
if ((l <= lMax) && (r >= rMax || arr[l] <= arr[r])) {
float[] t = arr.clone();
w[i3] = t[l];
arr = t.clone();
l++;
} else {
float[] t = arr.clone();
println(arr[r], t[r], w[i3]);
w[i3] = t[r];
println(arr[r], t[r], w[i3]);
arr = t.clone();
r++;
println();
}
}
}
it should just sort the elements of arr
but it seems to duplicate them whenever arr[r] < arr[l]