<algorithm> 中sort的使用
2013-04-15 11:01
288 查看
#include<iostream> #include<time.h> #include<algorithm> #include<cmath> using namespace std; #define N 10 struct position { int high; int low; }; bool operator <(position &a,position &b) { return a.low<b.low; } bool operator ==(position &a,position &b) { return (a.low==b.low)&&(a.high==b.high); } int main() { position temp[100]; int i; srand((unsigned )time(NULL)); for (i=0;i<N;i++) { temp[i].low=rand()%10; temp[i].high=rand()%10; } for (i=0;i<N;i++) { cout<<temp[i].low <<" "<<temp[i].high<<endl; } cout<<endl; sort(temp,temp+N); for (i=0;i<N;i++) { cout<<temp[i].low <<" "<<temp[i].high<<endl; } cout<<endl; return 0; }
相关文章推荐
- ASP.NET List<>中Sort()、Find()、FindAll()、Exist()的使用方法
- STL: <algorithm>中 sort()
- 使用Collections.sort(List<T>,Comparator<T>)给List<String>排序(一)
- 实战c++中的vector系列--使用sort算法对vector<unique_ptr<string>>进行排序(sort函数出错“应输入 2 个参数,却提供了 3 个)
- 【转】List<T>的Sort,Find,Exists等的使用
- [1_3_milk] O(n) algorithm <Count sort>
- 实战c++中的vector系列--使用sort算法对vector<unique_ptr<string>>进行排序(sort函数“应输入 2 个参数,却提供了 3 个)
- 剑指Offer——巧妙使用sort(List<T>,Comparator<? super T>)比较器
- #include <algorithm>中sort的一般用法
- <algorithm>find函数使用
- <algorithm.h>中sort对结构体排序的用法
- <algorithm.h>中sort对结构体排序的用法
- 剑指Offer——巧妙使用sort(List<T>,Comparator<? super T>)比较器
- List<>中Sort()、Find()、FindAll()、Exist()的使用方法
- #include <algorithm>中sort的一般用法
- 使用Collections.sort(List<T>,Comparator<? super T>)给List<String>排序(一)
- 使用Collections.sort(List<T>,Comparator<? super T>)给List<String>排序
- [C#/ASP.NET]List<>中Sort()、Find()、FindAll()、Exist()的使用方法
- C++<algorithm>中sort的比较函数写法
- 实战c++中的vector系列--使用sort算法对vector进行排序(对vector<string>排序、使用稳定的排序std::stable_sort())