您的位置:首页 >> 软件资讯 >> 编程开发 >> 文章正文

C语言编程开发 C语言库函数的简单介绍 函数名: qsort

2008-10-30 9:37:53 来源:本站原创 作者:佚名 点击:17

函数名: 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) );
}

上一篇: C语言基础教程 C语言的库函数 函数名: parsfnm
下一篇:

文章评论[我要评论]

此文章暂无评论