#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的更多相关文章

  1. DataStructure 排序 源码实现

    本篇博客实现了 1.冒泡排序 2.冒泡排序的一种优化(当某次冒泡没有进行交换时,退出循环) 3.选择排序 4.归并排序 5.快速排序. 主要是源码的实现,并将自己在敲的过程中所遇到的一些问题记录下来. ...

  2. 简单排序算法 C++类实现

    简单排序算法: 冒泡排序 插入排序 选择排序 .h代码: // // SortClass.h // sort and selection // // Created by wasdns on 16/1 ...

  3. 学习笔记之C++入门到精通(名师教学·手把手教会)【职坐标】_腾讯课堂

    C++入门到精通(名师教学·手把手教会)[职坐标]_腾讯课堂 https://ke.qq.com/course/101465#term_id=100105503 https://github.com/ ...

  4. 【Sort Colors】cpp

    题目: Given an array with n objects colored red, white or blue, sort them so that objects of the same ...

  5. 【Sort List】cpp

    题目: Sort a linked list in O(n log n) time using constant space complexity. 代码: /** * Definition for ...

  6. 53. 特殊的O(n)时间排序[sort ages with hashtable]

    [本文链接] http://www.cnblogs.com/hellogiser/p/sort-ages-with-hashtable.html [题目] 某公司有几万名员工,请完成一个时间复杂度为O ...

  7. HDU1890 Robotic Sort[splay 序列]

    Robotic Sort Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  8. 将三维空间的点按照座标排序(兼谈为std::sort写compare function的注意事项)

    最近碰到这样一个问题:我们从文件里读入了一组三维空间的点,其中有些点的X,Y,Z座标只存在微小的差别,远小于我们后续数据处理的精度,可以认为它们是重复的.所以我们要把这些重复的点去掉.因为数据量不大, ...

  9. 数据结构 - 归并排序(merging sort)

    归并排序(merging sort): 包含2-路归并排序, 把数组拆分成两段, 使用递归, 将两个有序表合成一个新的有序表. 归并排序(merge sort)的时间复杂度是O(nlogn), 实际效 ...

随机推荐

  1. window跳转页面

    1.直接的事件跳转 window.location.href="你所要跳转的页面"; 2.新窗口跳转 window.open('你所要跳转的页面'); 3.返回上一页 window ...

  2. mysql存储过程中 乱码问题解决办法

    中文乱码无论在何时都是一个头疼的问题,mysql的存储过程参数也同样存在这个问题.1.直接使用insert into语句没问题,能够正常插入汉字.2.把insert into语句移到Procedure ...

  3. 动态页面 servlet

    1.常见软件架构. C/S: 客户端 服务器  安全性较好,但是升级需要升级两端   B/S: 浏览器 服务器  安全性较差, 但是升级时 只需要升级服务器端(我们今后就是开发这个架构的) 2.资源分 ...

  4. cf593c

    题意:有n(n<=50)个圆,给出每个圆的圆心坐标和半径r(r>=2). 求两个函数f(t),g(t),t的取值为0到50的整数,每次令x=f(t),y=g(t),产生一个51个点的集合. ...

  5. 【安装MongoDB】CentOS7 下安装NodeJs+Express+MongoDB+Redis

    MongoDB,V3.2版本,官网说的很详细,见链接:https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/ 1.创建 ...

  6. 模拟搭建Web项目的真实运行环境(三)

    一.解决Redis出现的RDB权限问题 当你在安装redis的时候,如果是使用超级用户root安装, 开启redis服务的时候没有用超级用户去开启, 在用客户端登录redis,然后使用shutdown ...

  7. hdu 1300 Pearls

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1300 思路:用dp[i]表示前i种花费最低的情况,则有dp[i]=min(dp[i],dp[j+1]+(( ...

  8. 我的c++学习(9)指针

    ◆ 1.指针变量的赋值.初始化与简单应用 ,y; y=; // y可以理解成该存储单元的当前名字 int *ip; // ip是一个指针(变量) ip=&y; // ip是存储空间y的地址 c ...

  9. Listener refused the connection with the following error 错误解决

    原文地址 :http://blog.csdn.net/zajin/article/details/17753351 做个备份: 查询数据库当前进程的连接数: select count(*) from ...

  10. 1.0 Quartz 2D 简介

    本文并非最终版本,如有更新或更正会第一时间置顶,联系方式详见文末 如果觉得本文内容过长,请前往本人 “简书”   Quartz2D须知:   (1)Quartz 2D是苹果官方的二维绘图引擎,同时支持 ...