c++的stack容器和queue容器

stack容器

#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
using namespace std;
//栈容器,先进后出
//存储基础数据类型
void test01()
{
	stacks;
	s.push(10);
	s.push(20);
	s.push(30);
	//输出栈顶元素
	while (!s.empty())
	{
		cout<name = name;
		this->age = age;
	}

	string name;
	int age;
};
void test02()
{
	stacks;
	s.push(maker("hhh", 18));
	s.push(maker("aaa", 20));
	while (!s.empty())
	{
		cout << "name:" << s.top().name << " " << "age:" << s.top().age << endl;
		s.pop();
	}
}

queue容器

#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
#include
using namespace std;
void test01()
{
	queueq;
	for (int i = 0; i < 5; i++)
	{
		q.push(i + 1);

	}
	cout << "front:" << q.front()<name = name;
		this->age = age;
	}

	string name;
	int age;
};
void test02()
{
	queueq;
	q.push(new maker("aaa", 18));
	q.push(new maker("bbb", 20));
	q.push(new maker("ccc", 23));
	while (!q.empty())
	{
		maker* m = q.front();
		cout << m->name << " " <age << endl;
		q.pop();
		delete m;
		
	}
}

你可能感兴趣的:(c++,开发语言)