#include
#include
template
class Sequence
{
public:
virtual void push(T x) = 0;
virtual void pop() = 0;
};
//栈
template
class Stack: public Sequence
{
public:
void push(T x){deque.push_back(x);}
void pop(){deque.pop_back();}
private:
std::deque
};
//队列
template
class Queue:public Sequence
{
public:
void push(T x) { deque.push_back(x);}
void pop() {deque.pop_front();}
private:
std::deque
};
int main()
{
Sequence
s1->push(1);
s1->pop();
Sequence
s2->push(1);
s2->pop();
delete s1;
delete s2;
}
了解一下C++中的template,可能对你有帮助
乘承揽百费毁坏好普智取角