Posted by stand on August 05, 1999 at 17:21:06:
In Reply to: Mergesort posted by Jason D. Burkert on August 05, 1999 at 16:51:58:
Try this.
mergesort(arr, temp, 0, n-1);
: I'm having trouble implementing Mergesort. When I execute mergesort on an array with random values, it returns a sorted array, however, the largest value from the original list has been replaced with a 0.
: For example, this is what happens...
: Elem arr[n] = [424, 21, 928, 7] //for the sake of example
: Elem temp[n] = []
: mergesort(arr, temp, 0, n);
: arr = [0, 7, 21, 424]; //it has been ordered correctly, but 928 was replaced with 0.
: I copied the code for mergesort from the book. I have checked and rechecked it. I have tried both implementations on page 243 and they are both doing the same thing. What's wrong?