(示例)使用快速排序函数qsort的例程
2004-12-09 06:34
429 查看
函数名: qsort
功 能: 使用快速排序例程进行排序
用 法: void qsort(void *base, int nelem, int width, int (*fcmp)());
程序例:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int sort_function( const void *a, const void *b);
char list[5][4] = { "cat", "car", "cab", "cap", "can" };
int main(void)
{
int x;
qsort((void *)list, 5, sizeof(list[0]), sort_function);
for (x = 0; x < 5; x++)
printf("%s/n", list[x]);
return 0;
}
int sort_function( const void *a, const void *b)
{
return( strcmp(a,b) );
}
功 能: 使用快速排序例程进行排序
用 法: void qsort(void *base, int nelem, int width, int (*fcmp)());
程序例:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int sort_function( const void *a, const void *b);
char list[5][4] = { "cat", "car", "cab", "cap", "can" };
int main(void)
{
int x;
qsort((void *)list, 5, sizeof(list[0]), sort_function);
for (x = 0; x < 5; x++)
printf("%s/n", list[x]);
return 0;
}
int sort_function( const void *a, const void *b)
{
return( strcmp(a,b) );
}
相关文章推荐
- [MSDN]如何利用qsort对CArray的继承类进行排序
- [转载]计算机科学技术学习引论
- 那只猫和那只兔
- 谈谈我做招聘的感受
- 数据库
- 我的学习总结
- 使用Eclipse开发J2EE应用
- J2EE学习笔记(8) 真是知易行难 初试Struts
- 本人BLOG的相关版权声明
- 源代码J2EE黄金组合
- 水滴石穿C语言之正确使用const
- 水滴石穿C语言之typedef的问题
- 水滴石穿C语言之static辨析
- 原来幸福很简单
- 水滴石穿C语言之指针综合谈
- 水滴石穿C语言之指针、数组和函数
- 水滴石穿C语言之内存使用
- C++程序设计语言编程风格演变史
- 水滴石穿C语言之编译器引出的问题
- C++ SDK+Symbian开发入门之应用程序