gpt4 book ai didi

c - C中数组的QSORT?

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

如果我有这样的数组:

2, 4, 6, 0, 0, 0, 0, 0, 0
  1. Is there a way I can use qsort by sorting just the first 3 elements, and leaving the rest untouched?
  2. Would qsort(arrNumbers, 3, sizeof(int), compare) do the job?
  3. Does specifying the number of elements lower than the full array cause only that number of elements to become sorted?

EDIT:My compare function is:

int comp(const int * a, const int * b)
if(a==b)
{
return 0;
}
else
{
if(a<b)
{
return -1;
}
else
{
return 1;
}
}

看起来对吗?

最佳答案

是的。

是的。*

是的。


* 假设您适本地定义了 compare()

关于c - C中数组的QSORT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8115350/

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