C的快速排序
据说c有个qsort的函数?怎么用,要用到什么库?
给你个例子看看
#include
#include
#include
int compare( const void *arg1, const void *arg2 );
int main( int argc, char **argv )
{
int i;
/* Eliminate argv[0] from sort: */
argv++;
argc–;
/* Sort remaining args using Quicksort algorithm: */
qsort( (void *)argv, (size_t)argc, sizeof( char * ), compare );
/* Output sorted list: */
for( i = 0; i < argc; ++i )
printf( " %s", argv[i] );
printf( "\n" );
}
int compare( const void *arg1, const void *arg2 )
{
/* Compare all of both strings: */
return _stricmp( * ( char** ) arg1, * ( char** ) arg2 );
}
- 暨南大学精品课程——数据结构
- 今天早上apache-da的技术面试