Skip to content

Instantly share code, notes, and snippets.

@philorocha
Last active June 15, 2018 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philorocha/6d9c3275d13a748a348205375817b8f5 to your computer and use it in GitHub Desktop.
Save philorocha/6d9c3275d13a748a348205375817b8f5 to your computer and use it in GitHub Desktop.
/*Fila dinamica funcional*/
#include <stdio.h>
#include <stdlib.h>
typedef struct No{
int valor;
struct No* proximo;
} No;
No* inserir(No* no, int valor) {
if (no == NULL) {
No* novo = (No*)malloc(sizeof(No));
novo->valor = valor;
novo->proximo = NULL;
return novo;
} else {
no->proximo = inserir(no->proximo, valor);
return no;
}
}
No* remover(No* no) {
if (no == NULL) {
return NULL;
} else {
No* temp = no;
no = no->proximo;
free(temp);
return no;
}
}
int main(void) {
No* fila = NULL;
fila = inserir(fila, 10);
inserir(fila, 20);
inserir(fila, 30);
inserir(fila, 40);
fila = remover(fila);
while (fila != NULL) {
printf("%d\n", fila->valor);
fila = fila->proximo;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment