栈
作者:
lieon | 来源:发表于
2021-01-12 00:21 被阅读0次

image.png
template<class E>
class AStack {
ArrayList<E> *list { nullptr };
public:
AStack() {
list = new ArrayList<E>();
}
~AStack() {
if (list != nullptr) {
delete list;
list = nullptr;
}
}
E top() {
if (list->m_size > 0) {
return list->get(list->m_size - 1);
}
return NULL;
}
void push(const E &element) {
list->add(element);
}
E pop() {
return list->removeAt(list->m_size - 1);
}
bool isEmpty() {
return list->isEmpty();
}
void clear() {
list->clear();
}
};
本文标题:栈
本文链接:https://www.haomeiwen.com/subject/inzjaktx.html
网友评论