2012年6月2日
摘要: 简单贪心。用结构体数组存储数据。注意:1、qsort给double类型数据排序时注意要用return (*((struct node *)b1)).r > (*((struct node *)a1)).r? 1 : -1;用return (*((struct node *)b1)).r - (*((struct node *)a1)).r; 的话会报错的。CODE:1#include<stdio.h>2#include<stdlib.h>3#include<string.h>4#include<math.h>567constintsize= 阅读全文
posted @ 2012-06-02 20:01 有间博客 阅读(226) 评论(0) 推荐(0) 编辑
摘要: 以下是其具体分类及用法(若无具体说明是以降序排列):1、对一维数组排序:(Element_type是一位数组中存放的数据类型,可以是char, int, float, double, etc )使用qsort之前,必须自己定义一个比较函数。这个比较函数用于比较两个元素的大小。由于qsort可以排序任意数据类型,包括自定义的结构类型,因此,做一个自定义的比较函数是必要的。int Comp(const void *p1,const void *p2 ){ return *((Element_type *)p2) > *((Element_type *)p1) ? 1 : -1;}int ma 阅读全文
posted @ 2012-06-02 19:54 有间博客 阅读(415) 评论(0) 推荐(0) 编辑