I'm the beginner in C++. I try to write a program to rotate a vector one by one
i.e., {1,2,3,4,5} --> {2,3,4,5,1} --> {3,4,5,1,2}
vector<vector<int>> allrot(const vector<int>& a)
{
vector<vector<int>> result;
for (int i = 0; i < a.size(); i ++ ){
rotate(a.begin(), a.begin() + 1, a.end());
result.push_back(a);
}
return result;
}
This doesn't work, and I have several questions.
- Why should I use
vector<int>& arather thanvector<int> a? - What's wrong with my code ?
Thank you for your help
Aucun commentaire:
Enregistrer un commentaire