Mergesort not working

SimonN eiderdaus at gmail.com
Sun Dec 29 11:44:47 UTC 2019


On Sunday, 29 December 2019 at 11:02:34 UTC, Adnan wrote:
>     while (arr1_idx < arr1.length && arr2_idx < arr2.length)
>         result ~= arr1[arr1_idx] < arr2[arr2_idx] ? 
> arr1[arr1_idx++] : arr2[arr2_idx++];
>
> Given an array, it just returns a 1 length array. What's 
> causing this?

This loop stops as soon as arr1 _or_ arr2 are exhausted. Then, 
merge() will wrongly discard the remainder of the array that is 
not yet exhausted.

The templating is good!

-- Simon


More information about the Digitalmars-d-learn mailing list