-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_with_linked_list_stl.h
More file actions
54 lines (45 loc) · 1.3 KB
/
stack_with_linked_list_stl.h
File metadata and controls
54 lines (45 loc) · 1.3 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
#ifndef DATA_STRUCTURES_STACK_WITH_LINKED_LIST_STL_H
#define DATA_STRUCTURES_STACK_WITH_LINKED_LIST_STL_H
#include <list>
namespace DataStructures {
/**
* @class StackWithLinkedListSTL
* @brief Stack with STL linked list class with all related functionality.
* @tparam T Type of the implementation class.
*/
template <typename T>
class StackWithLinkedListSTL {
public:
/**
* @brief Push an element onto the top of the stack.
* @param element The element to be pushed.
*/
void push(const T& element) { list.push_back(element); }
/**
* @brief Pop an element from the top of the stack and return its value.
* @return The value of the popped element.
*/
T pop()
{
T top = list.back();
list.pop_back();
return top;
}
/**
* @brief Get the value of the top element of the stack.
* @return The value of the top element of the stack.
*/
T peek() const { return list.back(); }
/**
* @brief Get the size of the stack.
* @return Size of the stack.
*/
size_t size() const { return list.size(); }
private:
/**
* The doubly linked list used for internally implementing the stack.
*/
std::list<T> list;
};
} // namespace DataStructures
#endif // DATA_STRUCTURES_STACK_WITH_LINKED_LIST_STL_H