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

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,051 questions

40,769 answers

573 users

How to move the first element of a list to the end of the list in C++

1 Answer

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

using std::list;
using std::cout;

void printList(const list<int>& lst)
{
	for (auto elem : lst) {
		cout << elem << ' ';
	}
	cout << std::endl;
}

int main()
{
	list<int> lst{ 1, 2, 3, 4, 5 };

	lst.splice(lst.end(), lst, lst.begin());

	printList(lst);

	return 0;
}

/*
run:

2 3 4 5 1

*/

 





answered Jan 5, 2018 by avibootz
edited Jan 7, 2018 by avibootz

Related questions

...