lundi 25 octobre 2021

How to reverse a std::list at a given position?

I am trying to figure out how to reverse for example,grades{1, 2, 3, 4, 5, 6} starting at the third element.

I know for lists we cannot do (grades.begin() + 2) to obtain the position, but I'm not sure how to go about it. This is what I have so far, where I'm just reversing the entire list:

reverse(firstList.begin(), firstList.end());

I want it to be reverse so that the list becomes: grades{1, 2, 6, 5, 4, 3}

Aucun commentaire:

Enregistrer un commentaire