小编Chr*_*her的帖子

在 C 中创建大型数组时出现分段错误

你们在这段代码上给了我很大帮助。首先我要说的是,我不太了解 C,但我正在努力做到这一点。

这是程序应该做的事情:

  1. 创建长度为 1000 万的随机数列表
  2. 使用 shell 排序函数对随机数列表进行排序(仍然无法正常工作...我认为这就是我将指针传递给函数的方式)
  3. 列出一百万长的清单
  4. 记录时间时重复最多 1 亿次(由于某种原因时间显示为 0.0000000)

我只是想测试这个 shell 排序程序与标准库中内置的快速排序。

我尝试过使用和不使用指针。注释掉的部分在完成后应该可以工作。它只会让事情变得更加混乱,哈哈

请帮帮我,到目前为止你们都很棒......

#include <stdio.h>
#include <stdlib.h>
#include <time.h>


void shellSort(int *A, int n);
void checkSort(int *A, int n);

int main(){

    /*Initialize Random Array*/
    int unsorted_list[10000000];
    int *ptr = &unsorted_list[0];
    int random_number;
    int i;

    srand ( time(NULL) );
    for(i=0; i<10000000; i++){

        random_number = rand();
        unsorted_list[i] = random_number % 10000000;
    }

    //Do C Shell Sort
    double shell_results[10][2];

    double clock_diff;
    int j=10000000;
    clock_t t0, t1;
    int …
Run Code Online (Sandbox Code Playgroud)

c arrays sorting segmentation-fault

2
推荐指数
1
解决办法
2737
查看次数

标签 统计

arrays ×1

c ×1

segmentation-fault ×1

sorting ×1