all kinds of containers

#include <iostream>
#include <stack>
#include <vector>
#include <queue>
#include <list>
#include <map>
using namespace std;
int main()
{
	std::stack<int> stk;
	std::vector<int> vct;
	std::queue<int>	qq;
	std::list<int> lst;
	std::map<int, std::string> mp;
	for (int i = 0; i < 10; ++i)
	{
		stk.push(i);
	}
	for (int i = 0; i < 10; ++i)
	{
		vct.push_back(i);
	}
	int i = 0;
	// stack traverse;
	cout << endl << "stk traverse" << endl;
	//iterator<int> it = vct.begin();
	while (stk.size())
	{
		cout << stk.top();
		stk.pop();
	}
	//vct traverse
	cout << endl << "vct traverse" << endl;
	while (vct.size())
	{
		cout << vct.back();
		vct.pop_back();
		//vct pop_back()// stack; first in last out;
	}
	cout << endl;//front
	cout << "vct traverse2"<<endl;
	for (int i = 0; i < 10; ++i)
	{
		vct.push_back(i);
	}
	for (int i = 0; i < vct.size(); ++i)
	{
		cout << vct[i];
	}
	cout << "vct traverse3" << endl;
	for (vector<int>::iterator it = vct.begin();it!=vct.end(); ++it)
	{
		cout << (*it) << endl;
	}
	cout << endl;
	cout << endl << "queue traverse" << endl;
	for (int i = 0; i < 10; ++i)
	{
		qq.push(i);
	}
	while (qq.size())
	{
		cout << qq.front();
		qq.pop();
	}
	cout << endl;

	//========================
	for (int i = 0; i < 10; ++i)
	{
		lst.push_back(i);
	}
	cout << endl << "	list traverse" << endl;
	// list can access the front and the last ;
	// pop the front and the last;
	// main is the double direction linked list;
	cout << endl << "	list from front to end;" << endl;
	while (lst.size())
	{
		//cout << lst.back() << endl;
		//lst.pop_back();
		cout << lst.front();
		lst.pop_front();
		//cout << lst[2];
	}
	cout << endl << "	list from back to front;reverse out put;" << endl;
	for (int i = 0; i < 10; ++i)
	{
		lst.push_back(i);
	}
	while (lst.size())
	{
		cout << lst.back() << endl;
		lst.pop_back();
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值