Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Confused about a bit of code.

Name: Anonymous 2010-03-23 16:12

http://pastebin.org/121306

Could a friendly soul explain to me why removing/changing the for-loop at line 68-69 changes the whole program?
It changes output from   1 2 3 4 5   to   3 2 1 5 4 
if the input is 5 4 3 2 1

Name: Anonymous 2010-03-23 17:04

I don't actually know Java, but
>>5
You don't store a pointer to the sorted results, so when you merge L and R you are merging two unsorted lists.

for(int i = 0; i < q; i++)
    L[i] = A[i];

Doesn't Java have some sort of copy method for Arrays? Disgusting.

int output[] = new int[A.length];
output = merge(L, R, output);

Isn't this constructor call wasted?

Name: Anonymous 2010-03-23 17:56

As for the pointer. It doesn't seem to be needed. I tried that solution at first, but currently, it gives the correct result as it is.

As for the copy? I don't know. Not that into Java yet.

As for the constructor? I think you're right.


But I don't think that explains the anomaly I'm experiencing.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List