gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 03:47:43 25 4
gpt4 key购买 nike

我有一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com