C/C++ 中的qsort函数使用
来源:互联网 发布:mac os 10.13.1黑苹果 编辑:程序博客网 时间:2024/06/05 08:49
最近遇到了qsort函数,用于排序的
下面直接给一个例子说明
代码如下:
// qsort.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"/* qsort example */#include <stdio.h> /* printf */#include <stdlib.h> /* qsort */int values[] = { 40, 10, 100, 90, 20, 25 };int compare (const void * a, const void * b){ if( *(int*)a > *(int*)b ) return -1;if( *(int*)a == *(int*)b ) return 0;if( *(int*)a < *(int*)b ) return 1;}int main (){ int n; qsort (values, 6, sizeof(int), compare); for (n=0; n<6; n++) printf ("%d ",values[n]); return 0;}
结果为:
当compare函数为:
int compare (const void * a, const void * b){ if( *(int*)a < *(int*)b ) return -1;if( *(int*)a == *(int*)b ) return 0;if( *(int*)a > *(int*)b ) return 1;}
结果为:
参考
1.http://www.cplusplus.com/reference/cstdlib/qsort/
2.C语言qsort的用法
0 0
- C中的qsort函数
- C中的qsort函数
- C/C++ 中的qsort函数使用
- c中的qsort使用
- c语言中的Qsort函数
- C语言中的qsort函数
- C语言qsort函数使用
- c/c++ sort函数、qsort函数使用
- C/C++中的qsort()函数及其cmp()
- C语言qsort函数的使用
- C语言qsort函数如何使用
- c语言中的qsort方法的使用
- C语言 qsort() 函数
- C语言--qsort函数
- C语言---qsort函数
- C语言qsort()函数
- C/C++ qsort()函数
- C qsort函数
- Derson Number
- Java内存空间划分初识(适合初学者)
- Android数据存储之一SharedPreferences共享参数类
- 8个超实用的jQuery技巧
- Hadoop版本变迁
- C/C++ 中的qsort函数使用
- Android控件之Menu
- 选车牌号码
- 图的邻接表和邻接矩阵
- socket ioctl socket options struct ifreq; struct ifconf
- [朝花夕拾]在SourceInsight中集成版本管理工具
- 一路Hadoop-- 2、先让Linux系统跑起来
- Cocos2d-X移植时android.mk文件的处理方式
- 第二节 14年3,for函数