小编Het*_*tel的帖子

为什么这个合并排序不起作用?它给出相同的未排序数组

我编写了这段代码来实现合并排序,它从用户处获取输入数组并使用合并排序对该数组进行排序。但它会给出与输入相同的输出。

我还将临时数组 ( temp[]) 复制到array[].

请检查我的代码并给我解决方案,谢谢。

#include <stdio.h>

void merge(int array[], int mid, int low, int high) {
    int i, j, k, temp[100];
    
    i = low;
    k = low;
    j = mid + 1; 
    
    while (i <= mid && j <= high) {
        if (array[i] < array[j]) {
            temp[k] = array[i];
            i++;
            k++;
        } else {
            temp[k] = array[j];
            j++;
            k++;
        }
    }
    
    while (i <= mid) {
        temp[k] = array[i];
        i++;
        k++;
    }
    
    while (j <= …
Run Code Online (Sandbox Code Playgroud)

c sorting merge data-structures

0
推荐指数
1
解决办法
65
查看次数

标签 统计

c ×1

data-structures ×1

merge ×1

sorting ×1