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();
}
};
网友评论