forked from matheusfer0902/Simulador-ED
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFilaSeq.cpp
79 lines (62 loc) · 1.4 KB
/
FilaSeq.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* FilaSeq.cpp
*
* Created on: 10 de nov. de 2022
* Author: Administrador
*/
#include "FilaSeq.h"
FilaSeq::FilaSeq() {
nElementos = 0;
}
FilaSeq::~FilaSeq() {
}
/** Verifica se a Fila está vazia */
bool FilaSeq::vazia() {
return (nElementos == 0);
}
/**Verifica se a Fila está cheia */
bool FilaSeq::cheia() {
return (nElementos == TAM_MAX);
}
/** Obtém o tamanho da Fila */
int FilaSeq::tamanho() {
return nElementos;
}
/** Consulta o elemento do início da fila.
* Retorna -1 se a fila estiver vazia. */
string FilaSeq::primeiro() {
if (vazia())
return NULL; // Erro: Fila vazia
return dados[0];
}
/**Insere um elemento no fim de uma fila
Retorna false se a fila estiver cheia, true caso contrário. */
bool FilaSeq::insere(string nome) {
if (cheia())
return false;
dados[nElementos] = nome;
nElementos++;
return true;
}
/**Remove o elemento do início da fila e retorna o valor removido.
* Retorna -1 se a fila estiver vazia.*/
string FilaSeq::remove() {
if (vazia())
return NULL;
// Guarda o valor a ser removido
//int valor = primeiro();
string nome = dados[0];
nElementos--;
for (size_t i = 0; i < nElementos; i++)
{
dados[i] = dados[i+1];
}
return nome;
}
string FilaSeq::sequencia(int ordem)
{
if(ordem <= nElementos && ordem >= 0)
return dados[ordem];
else
return NULL;
}