#include
#include
using namespace std;
int main()
{
stacks1; s1.push(10); //入栈 s1.push(20); s1.push(30); s1.push(40); cout << s1.size()< }
queue容器#include
#include
using namespace std;class Person{
public:
string name;
int age;
Person(string name,int age) {
this->name = name;
this->age = age;
}
};int main()
{
queue q;Person p1("唐僧", 25); Person p2("孙悟空",700); Person p3("猪八戒",650); Person p4("沙僧", 525); q.push(p1); //入队 q.push(p2); q.push(p3); q.push(p4); cout << "队列大小:" << q.size() << endl; while (!q.empty()) { cout << "队头元素姓名为:" << " " << q.front().name << " " << "队头元素年龄为:" << q.front().age << endl; cout << "队尾元素姓名为:" << " " << q.back().name << " " << "队尾元素年龄为:" << q.back().age << endl; q.pop(); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)