Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "Fila.h"
- struct No * inserir(struct No *q, int num){
- struct No * anterior = q;
- struct No *novo = (struct No*)malloc(sizeof(struct No));
- if(novo == NULL){
- printf("Erro de alocacao\n");
- return q;
- }
- novo->num = num;
- if(q==NULL){
- novo->prox = NULL;
- q = novo;
- return q;
- }
- while(anterior->prox != NULL)
- anterior = anterior->prox;
- novo->prox = NULL;
- anterior->prox = novo;
- return q;
- }
- struct No *remover(struct No *q, int *num){
- struct No * tmp = q;
- if(q == NULL){
- printf("Fila vazia\n");
- return q;
- }
- *num = q->num;
- if(tmp->prox == NULL){
- free(tmp);
- q = NULL;
- return q;
- }
- tmp = q;
- q = q->prox;
- free(tmp);
- return q;
- }
- int tamanho(struct No *q){
- struct No *anterior = q;
- int cont = 1;
- if(q==NULL){
- printf("Fila vazia\n");
- return 0;
- }
- while(anterior->prox != NULL){
- cont++;
- anterior = anterior->prox;
- }
- return cont;
- }
- void imprimir(struct No *q){
- struct No *anterior = q;
- if(q==NULL){
- printf("Fila vazia\n");
- return;
- }
- printf("%d ",anterior->num);
- while(anterior->prox != NULL){
- printf("-->%d ",anterior->prox->num);
- anterior = anterior->prox;
- }
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement