Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "Fila.h"
- using namespace std;
- struct fila
- {
- int inicio;
- int itens[TAM_MAX];
- int fim;
- };
- Fila* criar()
- {
- Fila* f = (Fila*)malloc(sizeof(Fila));
- f->inicio = 0;
- f->fim = 0;
- return f;
- }
- void destruir(Fila* f)
- {
- if (f != NULL) free(f);
- }
- void enfileirar(Fila* f, int valor)
- {
- if (f != NULL)
- {
- if (tamanho(f) == TAM_MAX)
- {
- cout << "Fila lotada!\n";
- return;
- }
- if (f->fim == TAM_MAX)
- {
- int a;
- for (a = 0; a < tamanho(f); a++)
- {
- f->itens[a] = f->itens[f->inicio + 1];
- }
- f->inicio = 0;
- f->fim = a;
- cout << "Inicio: " << f->inicio << " | Fim: " << f->fim << "\n";
- }
- f->itens[f->fim++] = valor;
- }
- }
- int desenfileirar(Fila* f)
- {
- if (f != NULL)
- {
- if (tamanho(f) == 0)
- {
- cout << "Fila vazia!\n";
- return -1;
- }
- return f->itens[f->inicio++];
- }
- }
- int primeiro(Fila* f)
- {
- if (f != NULL)
- {
- if (tamanho(f) == 0)
- {
- cout << "Fila vazia!\n";
- return -1;
- }
- }
- return f->itens[f->inicio];
- }
- int tamanho(Fila* f)
- {
- if (f != NULL) return (f->fim) - (f->inicio);
- return -1;
- }
- void exibirFila(Fila* f)
- {
- cout << "Status da fila: [ ";
- if(tamanho(f) == 0)
- {
- cout << "Fila vazia! ]\n";
- return;
- }
- for (int a = f->inicio; a < f->fim; a++)
- {
- cout << f->itens[a] << " ";
- }
- cout << " ]\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement