-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_with_linked_list.h
More file actions
53 lines (44 loc) · 1.29 KB
/
stack_with_linked_list.h
File metadata and controls
53 lines (44 loc) · 1.29 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
#ifndef DATA_STRUCTURES_STACK_WITH_LINKED_LIST_H
#define DATA_STRUCTURES_STACK_WITH_LINKED_LIST_H
#include "doubly_linked_list.h"
namespace DataStructures {
/**
* @class StackWithLinkedList
* @brief Stack with linked list class with all related functionality.
* @tparam T Type of the implementation class.
*/
template <typename T>
class StackWithLinkedList {
public:
/**
* @brief Push an element onto the top of the stack.
* @param element The element to push.
*/
void push(const T& element) { list.add_last(element); }
/**
* @brief Pop the element at the top of the stack and return its value.
* @return Value of the popped element.
*/
T pop()
{
T top = list.del_last();
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.get_last(); }
/**
* @brief Get the size of the stack.
* @return Size of the stack.
*/
size_t size() const { return list.get_size(); }
private:
/**
* The doubly linked list used for internally implementing the stack.
*/
DoublyLinkedList<T> list;
};
} // namespace DataStructures
#endif // DATA_STRUCTURES_STACK_WITH_LINKED_LIST_H