vetor 结构体元素排序
来源:互联网 发布:我的淘宝好评怎么删除 编辑:程序博客网 时间:2024/05/21 09:32
sort struct:
#include <iostream>#include <vector>#include <algorithm>using namespace std;typedef struct example{ int elem1; int elem2;}example;/*这个comparison函数很重要.如果希望升序排序,就是"<",降序排列就是">"号,这样便于直观记忆.如果希望用elem2作为比较标准就把elem1改为elem2,这样结构体就以elem2为比较标准排序了.*/ bool comparison(example a,example b){ return a.elem1<b.elem1;}int main(){ int N; cin>>N; vector<example> array(N); for(int i=0;i<N;i++) { cin>>array[i].elem1>>array[i].elem2; } sort(array.begin(),array.end(),comparison); for(int i=0;i<N;i++) { cout<<array[i].elem1<<" "<<array[i].elem2<<endl; } return 0;}
0 0
- vetor 结构体元素排序
- STL之vetor 排序
- vetor
- STL中list结构体元素排序
- 对vector 中的结构体元素排序
- C++对结构体元素排序
- C++对结构体按照某一项元素进行排序
- STL-有关list元素为结构体,而按其中一元素排序问题
- list元素为结构体,而按其中一元素排序问题
- vector元素为自定义结构体类型时如何对容器元素进行排序?
- vector元素为自定义结构体类型时如何对容器元素进行排序?
- vetor操作
- 结构体排序,多级排序
- 结构体成员排序
- 结构体数组排序
- 结构体排序
- 结构体学号排序
- 结构体数组排序
- Android Intent action有什么用???
- Sql Server 创建数据库脚本
- hdu 1297 Children’s Queue
- 小白学jquery Mobile《构建跨平台APP:jQuery Mobile移动应用实战》连载七-手机调查问卷
- nyoj 19【擅长排列的小明】
- vetor 结构体元素排序
- Git图形化参考手册
- js、sql server、oracle中时间函数的简单简介
- Activity生命周期 及 各个回调应该做什么事情
- js对象笔记(1)
- easyUI中的datagrid
- TIME_WAIT是什么?
- 使用YUM安装官方发布的MySQL数据库
- hashTable的学习