现在的位置: 首页 > 综合 > 正文

qsort 与 sort 对结构体排序

2018年04月04日 ⁄ 综合 ⁄ 共 254字 ⁄ 字号 评论关闭
struct circle
{
	int begin,end;
}circle[10002];
typedef struct circle CIR;
//qsort的比较函数
int cmp( const void *a,const void *b)
{
	return ((CIR*)a)->end - ((CIR*)b)->end;
}
//sort的比较函数
bool cmp1(CIR a, CIR b)
{
	return a.end < b.end;
}


sort(circle,circle+n,cmp1);

qsort(circle,n,sizeof(CIR),cmp);

抱歉!评论已关闭.