Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct No{
- int dado;
- struct No *proximo;
- };
- struct Fila{
- int tamanho;
- struct No *inicio;
- struct No *fim;
- };
- int iniciaFila(struct Fila *fila){
- fila->tamanho = 0;
- fila->inicio = NULL;
- fila->inicio = NULL;
- }
- void vaziaFila(struct Fila *fila){
- if(fila->tamanho == 0){
- return 1;
- }else{
- return 0;
- }
- }
- int tamanhoFila(struct Fila *fila){
- return fila->tamanho;
- }
- int primeiroFila(struct Fila *fila, int *dado){
- if(vaziaFila(fila)) return 0;
- *dado = (fila->inicio)->dado;
- return 1;
- }
- int insereFila(struct Fila *fila, int valor){
- struct No *novoNo;
- novoNo = malloc(sizeof(struct No));
- if(novoNo == NULL) return 0;
- novoNo->dado = valor;
- novoNo->proximo = NULL;
- if(vaziaFila(fila)){
- fila->inicio = novoNo;
- fila->fim = novoNo;
- }else{
- (fila->fim)->proximo = novoNo;
- fila->fim = novoNo;
- }
- fila->tamanho++;
- return 1;
- }
- int removeFila(struct Fila *fila, int *dado){
- struct No *aux;
- if(vaziaFila(fila)) return 0;
- if(fila->inicio == fila->fim){
- fila->fim = NULL;
- }
- *dado = (fila->inicio)->dado;
- aux = fila->inicio;
- fila->inicio = aux->proximo;
- free(aux);
- fila->tamanho--;
- return 1;
- }
- int mostraFila(struct Fila *fila){
- struct No *aux = fila->inicio;
- if(vaziaFila(fila)) return 0;
- printf("Tamanho da fila: %d elemento(s)\n", fila->tamanho);
- printf("----------------------------------\n");
- int indice = 1;
- while(aux != NULL){
- printf("\tPOSICAO: %d\n", indice);
- printf("\tVALOR: %d\n", aux->dado);
- aux = aux->proximo;
- indice++;
- printf("\n");
- }
- return 1;
- }
- int procuraFila(struct Fila *fila, int valor){
- if(vaziaFila(fila)) return -1;
- struct No *aux = fila->inicio;
- int posicao = 1;
- while(aux != NULL){
- if(aux->dado == valor){
- return posicao;
- }
- posicao++;
- aux = aux->proximo;
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement