BFLibCPP 0.1
CPP Library
Loading...
Searching...
No Matches
stack.hpp
Go to the documentation of this file.
1
6#ifndef STACK_HPP
7#define STACK_HPP
8
9#include "access.hpp"
10#include "list.hpp"
11
12namespace BF {
13
22template <typename T, typename S = int>
23class Stack : protected List<T, S> {
24public:
25 Stack() : List<T,S>() {
26
27 }
28
30
31 }
32
33 int push(T object) {
34 return this->add(object);
35 }
36
37 int pop() {
38 return this->deleteNode(this->last());
39 }
40
41 T top() {
42 typename List<T,S>::Node * n = this->last();
43 if (n) return n->object();
44 return 0;
45 }
46
47 S size() { return this->count(); }
48
49 bool empty() { return this->count() == 0; };
50};
51
52} // namespace BF
53
54#endif // STACK_HPP
55
Definition list.hpp:47
L object() const
Definition list.hpp:58
Definition list.hpp:41
int count() const
Definition list.hpp:104
Node * last() const
Definition list.hpp:229
int add(T obj)
Definition list.hpp:107
int deleteNode(Node *node)
Definition list.hpp:288
Definition stack.hpp:23
bool empty()
Definition stack.hpp:49
Stack()
Definition stack.hpp:25
~Stack()
Definition stack.hpp:29
S size()
Definition stack.hpp:47
T top()
Definition stack.hpp:41
int push(T object)
Definition stack.hpp:33
int pop()
Definition stack.hpp:37
Definition array.hpp:18