-
Notifications
You must be signed in to change notification settings - Fork 1
/
Stack.hpp
37 lines (27 loc) · 968 Bytes
/
Stack.hpp
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
#ifndef STACK_HPP
#define STACK_HPP
// DO NOT CHANGE THIS FILE
#include "LinkedList.cpp"
template <typename T>
class Stack
{
private:
LinkedList<T> _llist;
public:
Stack();
/// @brief push the items into the stack sequentially, where end of items is the top
Stack(const std::vector<T> &items);
/// @brief Returns the number of elements in the stack.
/// @return The number of elements in the stack.
size_t size() const;
/// @brief Returns the top element of the stack.
/// @return The value of the top element, or `std::nullopt` if the stack is empty.
std::optional<T> top() const;
/// @brief Adds an element to the top of the stack.
/// @param value: the value to be added
void push(T value);
/// @brief Removes the top element from the stack and returns that element.
/// @return The value of the popped element, or `std::nullopt` if the stack is empty.
std::optional<T> pop();
};
#endif