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

Trabalho De Pilhas Em C

Trabalho Universitário: Trabalho De Pilhas Em C. Pesquise 860.000+ trabalhos acadêmicos

Por:   •  13/11/2014  •  606 Palavras (3 Páginas)  •  204 Visualizações

Página 1 de 3

#include <stdio.h>

#include <conio.h>

#include <malloc.h>

#include <stdlib.h>

struct tpilha{

int dados;

struct tpilha *proximo;

};

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

/* procedimento push)*/

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

void push(struct tpilha **topo, int valor, int *sinal)

{

struct tpilha *p;

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

if (p == NULL){

*sinal = 0;

}

else{

p->dados = valor;

p->proximo = *topo;

*topo = p;

*sinal=1;

}

}

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

/* função pop */

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

int pop (struct tpilha **topo, int *sinal)

{

int valor;

struct tpilha *n;

if (*topo == NULL){

*sinal = 0;

}

else{

valor = (*topo)->dados;

n = *topo;

*topo = n->proximo;

free(n);

*sinal=1;

}

return valor;

}

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

/* retira par */

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

void retira_par(struct tpilha **tpilha1)

{

struct tpilha *tpilhaaux;

tpilhaaux = NULL;

int ok=1;

int valor;

while ((*tpilha1) != NULL)

{

if ((*tpilha1)->dados % 2 != 0){

push(&tpilhaaux, pop(tpilha1, &ok), &ok);

}

else{

printf("\n O numero %d foi removido da pilha 1!" , pop(tpilha1, &ok));

}

}

while (tpilhaaux != NULL){

push(tpilha1, pop(&tpilhaaux, &ok),

...

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