ScapeGoatTree
Loading...
Searching...
No Matches
stack.hpp
Go to the documentation of this file.
1//
2// Created by DELL on 03/01/2026.
3//
4
5#ifndef SCAPEGOATPROJECT_STACK_HPP
6#define SCAPEGOATPROJECT_STACK_HPP
7#include <stdexcept>
8#include "vector.hpp"
9
10template<typename T>
11class Stack {
13public:
17 void push(const T& value) {
18 data.push_back(value);
19 }
20
25 T pop() {
26 if (data.size() == 0) {
27 throw std::out_of_range("pop on empty Stack");
28 }
29 return data.pop_back();
30 }
31 T top() {
32 return data.data[0];
33 }
34
38 [[nodiscard]] unsigned int size() const {
39 return data.size();
40 }
41
45 [[nodiscard]] bool isEmpty() const {
46 return data.size() == 0;
47 }
48};
49
50
51#endif //SCAPEGOATPROJECT_STACK_HPP
Definition queue.hpp:9
Definition stack.hpp:11
bool isEmpty() const
Definition stack.hpp:45
Vector< T > data
Definition stack.hpp:12
void push(const T &value)
Definition stack.hpp:17
unsigned int size() const
Definition stack.hpp:38
T pop()
Definition stack.hpp:25
T top()
Definition stack.hpp:31