-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPilha.cpp
More file actions
54 lines (47 loc) · 1.21 KB
/
Pilha.cpp
File metadata and controls
54 lines (47 loc) · 1.21 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
#include "Pilha.h"
// Construtor da pilha
Pilha::Pilha(int tamMax) :tamMax(tamMax) { // Inicializa o tamanho máximo da fila
elementos = new int[tamMax]; // Aloca um vetor de elementos
topo = 0; // Inicializa a posição inicial do topo
}
// Destrutor da pilha
Pilha::~Pilha() {
delete[]elementos; // Desaloca o vetor de elementos
}
// Implementação da função que empilha um elemento
void Pilha::Empilha(int numero, bool& deuCerto) {
if (this->Cheia())
deuCerto = false;
else {
deuCerto = true;
elementos[topo] = numero;
topo++;
}
}
// Implementação da função para desempilhar um elemento
void Pilha::Desempilha(int& numero, bool& deuCerto) {
if (this->Vazia()) {
deuCerto = false;
}
else {
deuCerto = true;
numero = elementos[topo - 1];
topo--;
}
}
// Implementação da função que verifica se a pilha esta vazia
bool Pilha::Vazia() {
if (topo == 0) {
return true;
}
else return false;
}
bool Pilha::Cheia() {
if (topo == tamMax) {
return true;
}
else return false;
}
int Pilha::GetTamMax() {
return tamMax;
}