is_sorted
#include <algorithm>
#include <iostream>
#include <vector>
using std::vector,
std::is_sorted,
std::boolalpha,
std::cerr;
class Temp{
public:
int a, b;
Temp(int i, int j):a(i), b(j){}
bool operator < (Temp t){
if(this->a < t.a && this->b < t.b){
return true;
}
return false;
}
};
typedef vector<Temp> my_vector;
int main(){
cerr << boolalpha;
my_vector a = {Temp(16, 256), Temp(4, 16), Temp(12, 144), Temp(4, 16), Temp(19, 361), Temp(9, 81), Temp(3, 9), Temp(15, 225), Temp(5, 25), Temp(6, 36), Temp(1, 1), Temp(8, 64), Temp(13, 169), Temp(0, 0), Temp(2, 4), Temp(2, 4), Temp(3, 9), Temp(10, 100), Temp(18, 324), Temp(14, 196), Temp(17, 289), Temp(7, 49), Temp(11, 121)};
bool sorted = is_sorted(a.begin(), a.end());
cerr << "a is sorted: " << sorted << "\n";
auto test = [] (Temp a, Temp b)->bool{
if(a.a < b.a && a.b < b.b){
return true;
}
return false;
};
sorted = is_sorted(a.begin(), a.end(), test);
cerr << "a is sorted: " << sorted << "\n";
return 0;
}
C++ Examples© 2024 TBD