使用迭代器进行区间指定,注意start和end为前闭后开区间;sort函数内也可自行添加cmp比较函数,默认为从小到大排序。
#include <vector>
#include <algorithm>
using namespace std
;
int main(){
vector
<int>input
= { 1, 5, 2, 1, 3, 2, 5 };
auto start
= input
.begin()+2;
auto end
= start
+3;
sort(start
, end
);
for (auto itr
: input
){
cout
<< itr
<< " ";
}
cout
<< endl
;
return 0;
}
运行结果如下
转载请注明原文地址:https://blackberry.8miu.com/read-41384.html