-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1e1164
commit 57352f5
Showing
1 changed file
with
113 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// importando pacotes | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <stdbool.h> | ||
#include <malloc.h> | ||
|
||
// implementando estruturas | ||
|
||
typedef struct str | ||
{ | ||
int chave; | ||
struct str* prox; | ||
|
||
} NO; | ||
|
||
typedef struct | ||
{ | ||
NO* inicio; | ||
NO* fim; | ||
|
||
} FILA_DINAMICA; | ||
|
||
// declarando funcoes | ||
|
||
void inicializacao(FILA_DINAMICA *f); // ok | ||
void inserir(FILA_DINAMICA *f, int ch); // ok | ||
void exibir(FILA_DINAMICA *f); // ok | ||
|
||
int tamanho(FILA_DINAMICA *f); // ok | ||
int retirar(FILA_DINAMICA *f); // ok | ||
|
||
// implementando funcoes | ||
|
||
void inicializacao(FILA_DINAMICA *f) | ||
{ | ||
f->inicio = NULL; | ||
f->fim = NULL; | ||
|
||
} | ||
|
||
void exibir(FILA_DINAMICA *f) | ||
{ | ||
NO* aux = f->inicio; | ||
|
||
while(aux != NULL) | ||
{ | ||
printf("%d ", aux->chave); | ||
aux = aux->prox; | ||
|
||
} | ||
|
||
} | ||
|
||
int tamanho(FILA_DINAMICA *f) | ||
{ | ||
int tam = 0; | ||
NO* aux = f->inicio; | ||
|
||
while(aux != NULL) | ||
{ | ||
aux = aux->prox; | ||
tam++; | ||
|
||
} | ||
|
||
return (tam); | ||
|
||
} | ||
|
||
void inserir(FILA_DINAMICA *f, int ch) | ||
{ | ||
NO* novo = (NO*) malloc(sizeof(NO)); | ||
novo->chave = ch; | ||
novo->prox = NULL; | ||
|
||
if(f->inicio == NULL) f->inicio = novo; // lista vazia | ||
else f->fim->prox = novo; // lista com elem | ||
|
||
f->fim = novo; | ||
|
||
} | ||
|
||
int retirar(FILA_DINAMICA *f) | ||
{ | ||
if(f->inicio == NULL) | ||
{ | ||
return (-1); // lista vazia | ||
|
||
} else { | ||
|
||
int resp = f->inicio->chave; | ||
|
||
NO* aux = f->inicio; | ||
f->inicio = f->inicio->prox; | ||
free(aux); | ||
|
||
if(f->inicio == NULL) f->fim = NULL; | ||
|
||
return (resp); | ||
|
||
} | ||
|
||
} | ||
|
||
// funcao main | ||
|
||
int main() | ||
{ | ||
|
||
return 0; | ||
|
||
} |