To answer the question of a problem, it is necessary to determine whether the sequence is sorted in ascending order or there are violations of order in it. I do not know C ++ well and it would be clearer to write the list myself, but it would be more convenient to take a ready-made abstraction. What am I doing wrong when using iterators? In the last step, the iterator points to the very top of the list, and because of this, the result is incorrect.
#include <iostream> #include <list> #include <ctype.h> int main(){ std::list<int> balls; int n, ball, curr; bool cheater; std::cin >> n; while(!std::cin.eof()){ std::cin >> ball; balls.push_back(ball); } cheater = false; std::list<int>::iterator it = balls.begin(); while(it != balls.end()){ std::cout << *it << " "; curr = *it; if(curr >= *(++it)) cheater = true; std::cout << "curr = " << curr << ", it = " << *it << std::endl; curr = *it; //it++; }