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
10
template
<
typename
T>
11
class
Stack
{
12
Vector<T>
data
;
13
public
:
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
QNode
Definition
queue.hpp:9
Stack
Definition
stack.hpp:11
Stack::isEmpty
bool isEmpty() const
Definition
stack.hpp:45
Stack::data
Vector< T > data
Definition
stack.hpp:12
Stack::push
void push(const T &value)
Definition
stack.hpp:17
Stack::size
unsigned int size() const
Definition
stack.hpp:38
Stack::pop
T pop()
Definition
stack.hpp:25
Stack::top
T top()
Definition
stack.hpp:31
vector.hpp
CPP
stack.hpp
Generated by
1.9.8