void qsort(void *base,size_t nmem,size_t size, int (*cmp)(const void *p,const void *q));
int cmpint(const void *p,const void *q)
{
return *(int *)p - *(int *)q;
}
int cmpchar(const void *p,const void *q)
{
return strcmp((char*)p ,(char *)q);
}
int main()
{
int i=0;
int a[] = {9,8,6,7,8};
qsort(a,sizeof(a)/sizeof(int),sizeof(int),cmpint);
for(i=0;i<5;i++) printf("%d\n",a[i]);
char str[][10] = {"abc","bcde","ab"};
qsort(str,3,sizeof(str[0]),cmpchar);
for(i=0;i<3;i++)printf("%s\n",str[i]);
system("pause");
return 0;
}
阅读(1580) | 评论(0) | 转发(0) |