??????????????find_if_not???????????μ????????ж?????????????
?????????????????copy_if??????????????copy??????????ж?????????????????????????????????÷???
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
vector<int> v = { 1?? 3?? 5?? 7?? 9?? 4 };
std::vector<int> v1(v.size());
//????????????
auto it = std::copy_if(v.begin()?? v.end()?? v1.begin()?? [](int i){return i%2!=0;});
//????vector???????С
v1.resize(std::distance(v1.begin()??it));
for(int i : v1)
{
cout<<i<<" ";
}
cout<<endl;
}
??????????????iota????????????????????У??????????????????????飬????????е???????????????????????????????????iota?????????????????????????????????????÷???
#include <numeric>
#include <array>
#include <vector>
#include <iostream>
using namespace std;
int main()
{
vector<int> v(4) ;
//?????????????????????
//for(int i=1; i<=4; i++)
//{
//    v.push_back(i);
//}
//??????iota????????飬?????
std::iota(v.begin()?? v.end()?? 1);
for(auto n: v) {
cout << n << ' ';
}
cout << endl;
std::array<int?? 4> array;
std::iota(array.begin()?? array.end()?? 1);
for(auto n: array) {
cout << n << ' ';
}
std::cout << endl;
}
???????????
????1 2 3 4
????1 2 3 4
??????????????iota????????????????????????????????iota???????????????????С??????????????У?vector<int> v(4) ;?????????????С?4??????????????
???????????????????????????С?????minmax_element??????????????????????С???????÷?????max_element??max_element??????????????????minmax_element??С??????????????????pair?з??????????????????÷???
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
// your code goes here
vector<int> v = { 1?? 2?? 5?? 7?? 9?? 4 };
auto result = minmax_element(v.begin()?? v.end());
cout<<*result.first<<" "<<*result.second<<endl;
return 0;
}
???????????
????1 9
??????????????is_ sorted??is_ sorted_until????is_sort?????ж????????????????????is_sort_until??????????????????????????????????С????????????????÷???
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
vector<int> v = { 1?? 2?? 5?? 7?? 9?? 4 };
auto pos = is_sorted_until(v.begin()?? v.end());
for(auto it=v.begin(); it!=pos; ++it)
{
cout<<*it<< " ";
}
cout<<endl;
bool is_sort = is_sorted(v.begin()?? v.end());
cout<< is_sort<<endl;
return 0;
}
???????????
????1 2 5 7 9
????0
?????????Щ?????????????????????????????????????????