Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <time.h>
- #include <cstdlib>
- using namespace std;
- struct Par
- {
- int first, second;
- };
- bool comparar(const Par &a, const Par&b)
- {
- if(a.first < b.first)
- return true;
- if(a.first > b.first)
- return false;
- if(a.second < b.second)
- return true;
- return false;
- }
- Par constructor(int a, int b)
- {
- Par myPar;
- myPar.first = a;
- myPar.second = b;
- return myPar;
- }
- int main()
- {
- srand(time(0));
- vector <Par> myVec;
- for(int i=0; i<10; i++)
- {
- myVec.push_back(constructor(rand()%10, rand()%20));
- }
- for(int i=0; i<myVec.size(); i++)
- {
- cout << myVec[i].first << " " << myVec[i].second << endl;
- }
- sort(myVec.begin(), myVec.end(), comparar);
- cout << "ORDENADO: " << endl;
- for(int i=0; i<myVec.size(); i++)
- {
- cout << myVec[i].first << " " << myVec[i].second << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment