gpt4 book ai didi

c - qsort使用什么排序算法?

转载 作者:太空狗 更新时间:2023-10-29 16:59:10 26 4
gpt4 key购买 nike

我找不到任何关于 C qsort 函数使用的排序算法的信息。

是快排吗? man里面没有提到。

最佳答案

未指定qsort 的实现:一个实现可以使用任何排序算法。有趣的是,排序不需要稳定,也没有复杂度要求。

qsort (C11 §7.22.5.2) 的整个规范如下:

The qsort function

Synopsis

#include <stdlib.h>
void qsort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *));

Description

The qsort function sorts an array of nmemb objects, the initial element of which is pointed to by base. The size of each object is specified by size.

The contents of the array are sorted into ascending order according to a comparison function pointed to by compar, which is called with two arguments that point to the objects being compared. The function shall return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.

If two elements compare as equal, their order in the resulting sorted array is unspecified.

Returns

The qsort function returns no value.

关于c - qsort使用什么排序算法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13353904/

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