您的位置:首页 > 其它

C自带排序函数qsort()的使用

2010-04-19 13:39 183 查看
stdlib.h中提供了qsort()这个函数可以实现快速排序。
MSDN中的描述如下:
void qsort( void *base, size_t num, size_t width, int (__cdecl *compare )(const void *elem1, const void *elem2 ) );

Parameters
base
Start of target array
num
Array size in elements
width
Element size in bytes
compare
Comparison function
elem1
Pointer to the key for the search
elem2
Pointer to the array element to be compared with the key

Remarks
The qsort function implements a quick-sort algorithm to sort an array of num elements, each of width bytes. The argument base is a pointer to the base of the array to be sorted. qsort overwrites this array with the sorted elements. The argument compare is a pointer to a user-supplied routine that compares two array elements and returns a value specifying their relationship. qsort calls the compare routine one or more times during the sort, passing pointers to two array elements on each call:
compare( (void *) elem1, (void *) elem2 );
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: