CPP - sort
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class student{
public:
student(){}
student(int num, string str, int s) {id= num;name = str;score = s; }
student(student &stu){id = stu.id;name = stu.name;score = stu.score;}
int getid(){ return id; }
string getname(){ return name; }
int getscore(){ return score; }
bool operator < (const student &stu)const { return score < stu.score; }
bool operator > (const student &stu){ return score > stu.score; }
bool operator () (const student &stu1, const student &stu2){ return stu1.score > stu2.score; }
private:
int id;
string name;
int score;
}; int cmp( const void *a ,const void *b)
{
return ((student *)a)->getscore() - ((student *)b)->getscore() ;
} int main() {
int i;
student stu[5] = { student(1, "zhu", 86),student(2, "xing", 92),
student(3, "zhao", 78),student(4, "fu", 88),student(5, "liu", 76) };
qsort(stu,5,sizeof(stu[0]),cmp);
for(i=0;i<5;i++)
cout << stu[i].getid() <<" "<< stu[i].getname()<<" " << stu[i].getscore() << endl;
return 0;
}
CPP - sort的更多相关文章
- DataStructure 排序 源码实现
本篇博客实现了 1.冒泡排序 2.冒泡排序的一种优化(当某次冒泡没有进行交换时,退出循环) 3.选择排序 4.归并排序 5.快速排序. 主要是源码的实现,并将自己在敲的过程中所遇到的一些问题记录下来. ...
- 简单排序算法 C++类实现
简单排序算法: 冒泡排序 插入排序 选择排序 .h代码: // // SortClass.h // sort and selection // // Created by wasdns on 16/1 ...
- 学习笔记之C++入门到精通(名师教学·手把手教会)【职坐标】_腾讯课堂
C++入门到精通(名师教学·手把手教会)[职坐标]_腾讯课堂 https://ke.qq.com/course/101465#term_id=100105503 https://github.com/ ...
- 【Sort Colors】cpp
题目: Given an array with n objects colored red, white or blue, sort them so that objects of the same ...
- 【Sort List】cpp
题目: Sort a linked list in O(n log n) time using constant space complexity. 代码: /** * Definition for ...
- 53. 特殊的O(n)时间排序[sort ages with hashtable]
[本文链接] http://www.cnblogs.com/hellogiser/p/sort-ages-with-hashtable.html [题目] 某公司有几万名员工,请完成一个时间复杂度为O ...
- HDU1890 Robotic Sort[splay 序列]
Robotic Sort Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- 将三维空间的点按照座标排序(兼谈为std::sort写compare function的注意事项)
最近碰到这样一个问题:我们从文件里读入了一组三维空间的点,其中有些点的X,Y,Z座标只存在微小的差别,远小于我们后续数据处理的精度,可以认为它们是重复的.所以我们要把这些重复的点去掉.因为数据量不大, ...
- 数据结构 - 归并排序(merging sort)
归并排序(merging sort): 包含2-路归并排序, 把数组拆分成两段, 使用递归, 将两个有序表合成一个新的有序表. 归并排序(merge sort)的时间复杂度是O(nlogn), 实际效 ...
随机推荐
- 【转载总结】jQuery和HTML5全屏焦点图
选项设置与说明 Slider Revolution提供了很多参数选项设置: delay: 滑动内容停留时间.默认9000毫秒 startheight: 滑动内容高度,默认490像素. startwid ...
- SQLPULS : 密码中有特殊字符的处理方法
前日在使用SQLPLUS访问oracle数据库时,系统提示密码过期,需要更新密码.于是不假思索的修改密码为xxx@2016(估计当时脑子抽风了),造成了杯具的开始. 再次进入SQLPLUS,输入用户名 ...
- linux svn 搭建
原文:http://jingyan.baidu.com/article/3c343ff7039de20d37796306.html和http://blog.sina.com.cn/s/blog_670 ...
- 一些实用的Windows注册表
一些实用的Windows注册表 1.去掉快捷方式文件名后面自动添加的"-快捷方式" 在给某个文件创建快捷方式时(选中文件-->右键-->发送到-->桌面快捷方式) ...
- css笔记1: html页面的CSS、DIV命名规则
原地址:http://www.cnblogs.com/rising-fay/archive/2013/02/25/2932592.html CSS命名规则 头:header 内容:content/co ...
- 朴素贝叶斯算法的python实现
朴素贝叶斯 算法优缺点 优点:在数据较少的情况下依然有效,可以处理多类别问题 缺点:对输入数据的准备方式敏感 适用数据类型:标称型数据 算法思想: 朴素贝叶斯比如我们想判断一个邮件是不是垃圾邮件,那么 ...
- 参数max_allowed_packet
通信信息包是发送至MySQL服务器的单个SQL语句,或发送至客户端的单一行. 当MySQL客户端或mysqld服务器收到大于max_allowed_packet字节的信息包时,将发出“信息包过大”错误 ...
- 第二十八篇:SOUI中自定义控件开发过程
在SOUI中已经提供了大部分常用的控件,但是内置控件不可能满足用户的所有要求,因此一个真实的应用少不得还要做一些自定义控件. 学习一个新东西,最简单的办法就是依葫芦画瓢.事实上在SOUI系统中内置控件 ...
- UWP 下拉刷新控件(PullToRefreshControl)
最近项目里面有下拉刷新的需求,自己做了一个,效果还不错. <Style TargetType="local:PullToRefreshControl"> <Set ...
- Dubbo详细介绍与安装使用过程
今天看到一篇不错的dubbo介绍教程,原文链接:http://blog.csdn.net/xlgen157387/article/details/51865289 1 Dubbo介绍 1.1 dubb ...