Problem with Mergesort algorithm.
  Home FAQ Contact Sign in
alt.lang.delphi only
 
Advanced search
POPULAR GROUPS

alt.lang.delphi Profile…
 Up
Problem with Mergesort algorithm.         


Author: r030t1
Date: Aug 5, 2008 08:56

The code can be found here: http://pastebin.com/f7f49e556

I translated from a Java source, at the moment I can't find it, but if
I do I'll post it.

What my problems actually are is that, when run, the array is not in
the correct order... At the beggining, there may be a clump of
numbers, not in order, usually followed by large spaces of zeros and
maybe a few numbers
-- not in order.

If anyone could look through and tell me what's wrong, that'd be great!
1 Comment
Re: Problem with Mergesort algorithm.         


Author: Rob Kennedy
Date: Aug 5, 2008 17:51

r030t1@gmail.com wrote:
> The code can be found here: http://pastebin.com/f7f49e556
>
> I translated from a Java source, at the moment I can't find it, but if
> I do I'll post it.

Mergesort is a pretty basic algorithm. It shouldn't need translating
from other languages.

If you ever find the Java code, take another look at it. Does it have
something like this:

int i = 0;
int j = lo;
while (j <= med) {
B[i++] := A[j++];
}

I suspect it does. You've translated it wrong. Those are
*post*-increment operators. They evaluate to the *current* value of i
and j, not the incremented values. The first index assigned in B is 0,
not 1.

Now look at your code.
Show full article (1.50Kb)
no comments