Created
June 4, 2020 23:37
-
-
Save lesimoes/b38ce52ef6ce0940a9f49822b015f351 to your computer and use it in GitHub Desktop.
Fila
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
#include <stdio.h> | |
#define TAM 4 | |
struct fila { | |
int inicio, fim, tamanho; | |
char elemento[TAM]; | |
}Fila; | |
void iniciar (struct fila *F) { | |
printf("Iniciando a Fila"); | |
F->inicio = 0; | |
F->fim = -1; | |
F->tamanho = 0; | |
} | |
void inserir (struct fila *F, char valor) { | |
F->tamanho ++; | |
F->fim = (F->fim % (TAM - 1)) + 1; | |
F->elemento[F->fim] = valor; | |
} | |
char retirar (struct fila *F) { | |
F->tamanho --; | |
F->inicio = (F->inicio % (TAM -1)) + 1; | |
return F->elemento[F->inicio - 1]; | |
} | |
int main() { | |
iniciar(&Fila); | |
inserir(&Fila, 'R'); | |
inserir(&Fila, 'O'); | |
inserir(&Fila, 'M'); | |
inserir(&Fila, 'A'); | |
printf("\n %c ", retirar(&Fila)); | |
printf("\n %c", retirar(&Fila)); | |
printf("\n %c", retirar(&Fila)); | |
printf("\n %c", retirar(&Fila)); | |
printf("\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment