Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Hostgator 1 Penny

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


7,621 questions

10,674 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 by avibootz
...