Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,845 questions

51,766 answers

573 users

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
...