#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
// 打印向量的函数
template<typename Type>
void printVec(const vector<Type>& vec) {
cout << "[";
for (auto it = vec.begin(); it != vec.end(); ++it) {
if (it != vec.begin()) {
cout << ", ";
}
cout << *it;
}
cout << "]" << endl;
}
int main() {
vector<int> vec{ 1, 2, 3, 4, 5, 6, 7, 8, 9 };
cout << "Before rotate: ";
printVec(vec);
// 使用 auto 进行类型推导
auto first = vec.begin();
auto second = first + 2;
auto third = first + 6;
rotate(first, second, third);
cout << "After rotate: ";
printVec(vec);
system("pause");
return 0;
}
std::roate数组轮转
最新推荐文章于 2024-10-01 05:07:35 发布