gpt4 book ai didi

c - 如何找到 qsort() 的比较操作数?

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

如何找出 qsort 的比较操作数?

我有一个应该排序的指针数组。这个指针数组指向一个结构数组。

struct oristru {
char string1[TITLE_FIELDLENGTH];
char string2[AUTHORS_FIELDLENGTH];
short int 1;
};


const struct oristru oristrukts[] = { ...}

const struct oristru *temp_oristru[ARRAYLEN(oristrukts)];
struct oristru *p_sortst[ARRAYLEN(oristrukts)];

qsort(*p_sortst, ..);

最佳答案

假设您使用函数 fx() 进行排序

qsort(..., fx);

只需调整 fx()

// global var to count comparisons
unsigned long ncomp = 0;

int fx(const void *a, const void *b) {
ncomp++;
/* return ...; */
}

关于c - 如何找到 qsort() 的比较操作数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54813338/

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