#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. DES & 3DES 加密算法

    JAVA坑 跟其他公司java的对接口,一个细节对到吐血,具体: DesUtil.java(别人的反例) //package base_class; import java.io.IOExceptio ...

  2. Linux IO模式及 select、poll、epoll详解

    linux的IO调度文章==> https://segmentfault.com/a/1190000003063859?hmsr=toutiao.io&utm_medium=toutia ...

  3. Cordova phonegap开发环境搭建

    1.下载并安装Android Studio, 2.下载并安装nodejs 3.通过nodejs来安装cordova(npm install -g cordova ) 4.使用cordova来创建pho ...

  4. 使用jvisualvm.exe 的Btrace插件介绍/使用教程

    一.背景        在生产环境中可能经常遇到各种问题,定位问题需要获取程序运行时的数据信息,如方法参数.返回值.全局变量.堆栈信息等.为了获取这些数据信息,我们可以 通过改写代码,增加日志信息的打 ...

  5. Python之模块,迭代器与生成器

    本节涉及内容: 1. 迭代器和生成器 2. 递归 3. 字符串格式化 4. 模块 内置模块 自定义模块 第三方模块 5. 序列化的模块 json pickle (一). 迭代器和生成器: 迭代器:  ...

  6. 6.openstack之mitaka搭建网络节点

    部署网络服务 一:控制节点配置 1.建库建用户 mysql -u root -p CREATE DATABASE neutron; GRANT ALL PRIVILEGES ON neutron.* ...

  7. Qt: 时钟Demo

    其实是一个很简单的Demo,可以编译了拿NSIS打包.最近在做富文本编辑器和补C++不记得的东西吧,项目遥遥无期. //clock.pro #----------------------------- ...

  8. 关于 iOS 加密的一些详谈

    iOS 加密算法有那么几种,如 md5,sha1,AES,base64 和 rsa 等. 1. md5: MD5即Message-Digest Algorithm 5(信息-摘要算法5),用于确保信息 ...

  9. C# 获取时间差状态

    /// <summary> /// 根据时间获取时间状态 /// </summary> /// <param name="dt"></pa ...

  10. (转)nginx优化 实现10万并发访问量

    转自http://www.cnblogs.com/pricks/p/3837149.html 一般来说nginx配置文件中对优化比较有作用的为以下几项:worker_processes 8;1 ngi ...