filas encadeadas

#include <stdio.h> #include <stdlib.h> struct no { int dado; struct no *prox; }; typedef struct no* tipofila; void INIT (tipofila *inicio,tipofila *fim) { *inicio=NULL; *fim=NULL; } int IsEmpty(tipofila ini, tipofila fim) { if ( (ini == NULL) && (fim==NULL)) return 1; else return 0; } void ENQUEUE(tipofila *inicio, tipofila *fim, int v) { tipofila novo; novo=(tipofila) malloc (sizeof(struct no)); if (novo==NULL) printf("Fila Cheia \n"); else { novo->dado=v; novo->prox=NULL; if (IsEmpty(*inicio,*fim)){ *inicio = novo; } else{ (*fim)->prox= novo; } *fim=novo; } } int FIRST(tipofila inicio, tipofila fim, int *v) { if(!IsEmpty(inicio,fim)) { *v = inicio->dado; return 1; } else return 0; } int DEQUEUE(tipofila *inicio, tipofila *fim, int *v) { tipofila aux = *inicio; if(!IsEmpty(*inicio,*fim)) { *v = (*inicio)->dado; (*inicio) = (*inicio)->prox; free (aux); if (*inicio == NULL) *fim = NULL; return 1; } else return 0; } int main(){ tipofila inicio, fim; int valor; INIT(&inicio, &fim); ENQUEUE(&inicio, &fim, 1); ENQUEUE(&inicio, &fim, 2); if (DEQUEUE(&inicio, &fim, &valor)==1) printf("valor = %d", valor); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.