1.栈stack
1.stack基本概念
2.stack常用接口
代码示例:
#include<bits/stdc++.h>
using namespace std;int main()
{stack<int> stk;stk.push(7);stk.push(9);stk.push(5);cout << "栈的size为:" << stk.size() << endl;while(!stk.empty()){cout << stk.top() << " ";stk.pop();}cout << endl << "栈现在的大小为:" << stk.size() << endl;return 0;
}
2.队列queue
1.queue基本概念
2.queue常用接口
代码示例:
#include<bits/stdc++.h>
using namespace std;class person
{
public:person(int age,int score){this -> age = age;this -> score = score;}int age;int score;
};int main()
{queue<person> q;person p1(18,115);person p2(19,130);person p3(20,150);q.push(p1);q.push(p2);q.push(p3);cout << "队列大小为:" << q.size() << endl << endl;while(!q.empty()){cout << "队头age为:" << q.front().age << "score为:" << q.front().score << endl;cout << "队尾age为:" << q.back().age << "score为:" << q.back().score << endl;cout << endl;q.pop();}cout << "队列大小为:" << q.size() << endl;return 0;
}