queue.h
#include<vector>
#include<list>
namespace Ljw
{
template<class T,class Container=vector<int>>
class queue//默认list的
{
public:
T& front()
{
return _con.front();
}
void push(const T&x)
{
_con.push_back(x);
}
void pop()
{
//_con.pop_front();//vecot没有头删,因为代价太大了,要想强制匹配用erase
_con.erase(_con.begin());
}
T& back()
{
return _con.back();
}
private:
Container _con;
};
void test1()
{
queue<int, list<int>> pq;
pq.push(1);
pq.push(2);
pq.push(3);
pq.pop();
cout << pq.front() << endl;
cout << pq.back() << endl;
queue<int, vector<int>> pq1;
pq1.push(1);
pq1.push(2);
pq1.push(3);
pq1.pop();
cout << pq1.front() << endl;
cout << pq1.back() << endl;
}
}
test.c
#include<iostream>
using namespace std;
#include"queue.h"//必须在下面,因为编译的时候.h只会往上找
int main()
{
Ljw::test1();
return 0;
}