stack:
#include <iostream>
#include <list>
#include <cstdlib>
template<class ElemType>
class Stack {
public:
ElemType Top() const {
return data_.back();
}
void Push(const ElemType &elem) {
data_.push_back(elem);
}
void Pop() {
data_.pop_back();
}
bool Empty() const {
return data_.empty();
}
private:
std::list<ElemType> data_;
};
list:
#include <iostream>
#include <list>
#include <cstdlib>
template<class ElemType>
class Queue {
public:
ElemType Front() const {
return data_.front();
}
void Push(const ElemType &elem) {
data_.push_back(elem);
}
void Pop() {
data_.pop_front();
}
bool Empty() const {
return data_.empty();
}
private:
std::list<ElemType> data_;
};
留言列表