How to reverse part of a list container with int numbers in C++

1 Answer

0 votes
#include <iostream>
#include <list>

int main()
{
	std::list<int> lst;

	for (int i = 10; i <= 30; i += 2) {
		lst.push_back(i);
	}

	for (auto elem : lst) {
		std::cout << elem << ' ';
	}
	std::cout << std::endl;
	
	auto indexvalue16 = find(lst.begin(), lst.end(), 16);

	reverse(indexvalue16, lst.end());

	for (auto elem : lst) {
		std::cout << elem << ' ';
	}
	std::cout << std::endl;

	return 0;
}

/*
run:

10 12 14 16 18 20 22 24 26 28 30
10 12 14 30 28 26 24 22 20 18 16

*/

 



answered Dec 30, 2017 by avibootz
...