-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_with_array_stl.h
More file actions
55 lines (46 loc) · 1.32 KB
/
stack_with_array_stl.h
File metadata and controls
55 lines (46 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef DATA_STRUCTURES_STACK_WITH_ARRAY_STL_H
#define DATA_STRUCTURES_STACK_WITH_ARRAY_STL_H
#include <vector>
namespace DataStructures {
/**
* @class StackWithArraySTL
* @brief Stack with STL array class and all related functionality.
* @tparam T Type of the the implementation class.
*/
template <typename T>
class StackWithArraySTL {
public:
/**
* @brief Push the element at the top of the stack.
* @param element The element to be pushed.
*/
void push(const T& element) { arr.push_back(element); }
/**
* @brief Pop the element from the top of the stack and return its
* value.
* @return The value of the element that has been popped.
*/
T pop()
{
T top = arr.back();
arr.pop_back();
return top;
}
/**
* @brief Get the value of the element at the top of the stack.
* @return The value of the element at the top of the stack.
*/
T peek() const { return arr.back(); }
/**
* @brief Get the current size of the stack.
* @return The current size of the stack.
*/
size_t size() const { return arr.size(); }
private:
/**
* The dynamic array used to internally implement the stack.
*/
std::vector<T> arr;
};
} // namespace DataStructures
#endif // DATA_STRUCTURES_STACK_WITH_ARRAY_H