1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #ifndef STACK_H
- #define STACK_H
- #include "data/List.h"
- template<typename T>
- class Stack final {
- List<T> data;
- public:
- template<typename... Args>
- Stack& push(Args&&... args) {
- data.add(std::forward<Args>(args)...);
- return *this;
- }
- void clear() {
- data.clear();
- }
- bool pop() {
- if(data.getLength() <= 0) {
- return true;
- }
- data.remove(data.getLength() - 1);
- return false;
- }
- bool isEmpty() const {
- return data.getLength() == 0;
- }
- T& peek() {
- return data[data.getLength() - 1];
- }
- const T& peek() const {
- return data[data.getLength() - 1];
- }
- template<int L>
- void toString(StringBuffer<L>& s) const {
- s.append(data);
- }
- };
- #endif
|