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,939 questions

51,876 answers

573 users

How to use list with push_back() and push_front() in C++

1 Answer

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

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

int main() 
{
	list<int> lst1, lst2;

	for (int i = 0; i < 5; i++)
		lst1.push_back(i);

	for (int i = 0; i < 5; i++)
		lst2.push_front(i);

	list<int>::iterator p;

	p = lst1.begin();
	while (p != lst1.end()) {
		cout << *p << " ";
		p++;
	}
	cout << endl;

	p = lst2.begin();
	while (p != lst2.end()) {
		cout << *p << " ";
		p++;
	}
	cout << endl;

	return 0;
}


/*
run:

0 1 2 3 4
4 3 2 1 0

*/

 



answered Apr 22, 2018 by avibootz

Related questions

2 answers 229 views
1 answer 110 views
1 answer 171 views
1 answer 165 views
...