TrabalhosGratuitos.com - Trabalhos, Monografias, Artigos, Exames, Resumos de livros, Dissertações
Pesquisar

Estruta De Dados - Fila

Monografias: Estruta De Dados - Fila. Pesquise 860.000+ trabalhos acadêmicos

Por:   •  25/5/2014  •  3.244 Palavras (13 Páginas)  •  356 Visualizações

Página 1 de 13

/*Enunciado: Escrever um procedimento que retira os valores primos de uma fila (com header).

Importante:

1) Não utilizar estrutura auxiliar !! Utilizar a mesma fila.

2) Fazer o procedimento em C para apresentar e fazer o programa principal que chame e teste este procedimento.*/

#include <stdio.h>

#include <malloc.h>

#include <stdlib.h>

struct fila{

int dado;

struct fila *proximo;

};

struct header{

struct fila *comeco;

int quantidade;

struct fila *final;

};

/*==============================

| CRIA_HEADER |

==============================*/

void cria_header (struct header **h1, int *sinal){

struct header *x;

x = (struct header * ) malloc (sizeof (struct header));

if ( x == NULL ){

*sinal = 1;

}else{

x->comeco = NULL;

x->final = NULL;

x->quantidade = 0;

*sinal = 0;

*h1 = x;

}

}

/*==============================

| ENFILEIRA |

==============================*/

void enfileira (struct header **f, int valor, int *sinal){

struct fila *aux, *p;

aux = NULL;

p = NULL;

p = (struct fila * ) malloc (sizeof (struct fila));

if (p == NULL){

*sinal = 1;

}else{

p->dado = valor;

p->proximo = NULL;

aux = (*f)->final;

(*f)->final = p;

if ((*f)->comeco == NULL){

(*f)->comeco = p;

}else{

aux->proximo = p;

}

(*f)->quantidade ++;

*sinal = 0;

}

}

/*==============================

| MOSTRA_FILA |

==============================*/

void mostra_fila(struct header **topo){ // verifica serve para informar se nao houve inserção de dados ou se nenhum é par

struct fila *aux;

aux = (*topo)->comeco;

if(aux == NULL){

printf("\n \n FILA : \n ");

printf("\n ***** ESTA FILA ESTA VAZIA POIS OS DADOS NAO FORAM INSERIDOS! ***** \n \n");

}else{

printf("\n \n VALORES INSERIDOS NA FILA : \n ");

while ( aux != NULL) /* Enquanto nao for final da lista... */ {

printf(" | %i | ",aux->dado);

aux = aux->proximo;

}

printf(" \n \n");

}

}

/*==============================

| MOSTRA_FILA_SEM_PRIMO |

==============================*/

void mostra_filasp(struct header **topo){ // verifica serve para informar se nao houve inserção de dados ou se nenhum é par

struct fila *aux;

aux = (*topo)->comeco;

if(aux == NULL){

printf("\n TODOS OS NUMEROS ERAM PRIMOS OU OS DADOS NAO FORAM INSERIDOS\n \n");

}else{

printf("\n \n VALORES NAO PRIMOS NA FILA: \n \n ");

while ( aux != NULL) /* Enquanto nao for final da lista... */ {

printf(" | %i | ",aux->dado);

aux = aux->proximo;

}

printf(" \n \n");

}

}

/*==============================

...

Baixar como (para membros premium)  txt (7.4 Kb)  
Continuar por mais 12 páginas »
Disponível apenas no TrabalhosGratuitos.com