Last active
December 3, 2023 14:10
-
-
Save divanibarbosa/279c739adcd244c35ac2e961b19c5a5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Criado por: profa. Divani Barbosa Gavinier | |
// Curriculo Lattes: http://lattes.cnpq.br/8503400830635447 | |
// [email protected] | |
#include <iostream> | |
using namespace std; | |
class FilaCircular { | |
private: double *itens; | |
int fim; | |
int tam_max; | |
int inicio; | |
int nItens; | |
public: FilaCircular (int tam) { | |
itens = new double[tam]; | |
tam_max = tam; | |
fim = -1; | |
inicio = 0; | |
nItens = 0; | |
} | |
bool empty() { return (nItens == 0 ); } | |
bool full() { return (nItens == tam_max ); } | |
int size() { return nItens; } | |
void enqueue(double valor) { | |
if (full()) { | |
cout << "\n >>> ATENCAO FILA CHEIA\n"; | |
return; | |
} | |
if (fim == tam_max-1) fim = -1; | |
fim++; | |
itens [ fim ] = valor; | |
nItens++; | |
} | |
double front() { | |
if (empty()) { | |
cout << "\n >>> ATENCAO FILA VAZIA\n"; | |
return 0; | |
} | |
return itens[ inicio ]; | |
} | |
void dequeue() { | |
if (empty()) { | |
cout << "\n >>> ATENCAO FILA VAZIA\n"; | |
return; | |
} | |
inicio++; | |
if (inicio == tam_max) inicio = 0; | |
nItens--; | |
} | |
}; // fim Classe FilaCircular | |
///////////////////////////////////////////////////////////// | |
int main() { // programa principal | |
cout << "Criando buffer com tamanho maximo 5."; | |
FilaCircular fc(5); | |
cout << "\nInserindo 4 itens no buffer: 10 - 20 - 30 - 40"; | |
fc.enqueue(10); | |
fc.enqueue(20); | |
fc.enqueue(30); | |
fc.enqueue(40); | |
cout << "\nRemovendo 3 itens do buffer:"; | |
cout << " " << fc.front(); | |
fc.dequeue(); | |
cout << " - " << fc.front(); | |
fc.dequeue(); | |
cout << " - " << fc.front(); | |
fc.dequeue(); | |
cout << "\nInserindo 3 itens no buffer: 50 - 60 - 70"; | |
fc.enqueue(50); | |
fc.enqueue(60); | |
fc.enqueue(70); | |
cout << "\nRemovendo todos os itens do buffer:"; | |
while (!fc.empty()) { // Ate esvaziar | |
cout << " " << fc.front(); // Mostre na tela o valor do inicio | |
fc.dequeue(); // retira um item da fila | |
} | |
cout << "\nRemovendo um item do buffer:"; | |
fc.dequeue(); // retira um item da fila | |
return 0; | |
} // fim programa principal aplicativo Fila Circular |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment