c - qsort : Sort 1 Dimension of 3D array in C

标签 c arrays sorting

我有一个 3D 数组:float input[2][50][1000];

我想快速排序:

qsort (x, sizeof(x)/sizeof(*x), sizeof(*x), comp);

补偿在哪里

int comp (const void * elem1, const void * elem2) {
    float f = *((float*)elem1);
    float s = *((float*)elem2);
    if (f > s) return  1;
    if (f < s) return -1;
    return 0;
}

我只想对我的 3D 数组的 1 维进行排序,即我想对 input[0][temp][0]input[0][temp][1 ], input[0][temp][2] 等等。

问题:我应该用什么替换x? 如果听起来很愚蠢,请原谅我

最佳答案

float (*x)[1000] = &input[0][temp];
qsort (x, sizeof(*x)/sizeof(**x), sizeof(**x), comp);

关于c - qsort : Sort 1 Dimension of 3D array in C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23027563/

相关文章:

创建一个可以使用 c fscanf 读取的文本文件

c - 在c中使用getch()仅将数字和字母作为输入

c++ - 如何优化这个将输入位转换为单词的简单函数?

arrays - 是否可以在 VBA 中定义结构体或对象的数组?

arrays - Fortran 2008 - 类中的数组变量

php - 可以访问键的array_map

c - 如果我无权访问文件,如何在 shell 中打开该文件?

javascript - 如果显式定义排序顺序,排序会非常慢

c++ - 固定大小的容器,其中元素已排序并可以提供指向 C++ 中数据的原始指针

找到正确索引的算法