且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

mergesort算法的输出问题

更新时间:2022-11-08 17:39:56

在最后两个while循环中,您的逻辑有误.
试试:
You have your logic wrong in the final two while loops.

try:
while (x < nums.Length)
{
    nums2[z] = nums[x];
    z++;
    x++;
}
while (y < nums1.Length)
{
    nums2[z] = nums1[y];
    z++;
    y++;
}



顺便说一句:不要忘记在开始合并之前确保对您的两个输入数组进行了排序.



BTW: Don''t forget to make sure that your two input arrays are sorted before starting the merge.