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

A Lista Exercícios Estrutura Dados em C

Por:   •  18/7/2021  •  Trabalho acadêmico  •  3.368 Palavras (14 Páginas)  •  173 Visualizações

Página 1 de 14

Exercício 04

#include <stdio.h>

#define TAM 20

struct tpilha

{ int topo;

float pilha[TAM];

};

void InicializaPilha(struct tpilha *ps)

{

ps -> topo = -1;

}

int PilhaVazia(struct tpilha *ps)

{

if (ps -> topo == -1)

return 1;

return 0;

}

int PilhaCheia(struct tpilha *ps)

{

if (ps -> topo == TAM-1)

return 1;

return 0;

}

int Empilha(struct tpilha *ps, int valor)

{

if (PilhaCheia(ps))

return 0;

ps -> topo++;

ps -> pilha[ps -> topo] = valor;

return 1;

}

void Desempilha(struct tpilha *ps, int *elem)

{

if (PilhaVazia(ps))

return;

*elem = ps -> pilha[ps -> topo];

ps -> topo--;

}

int main()

{

struct tpilha p1, p2, p3;

float n;

int i;

InicializaPilha(&p1);

InicializaPilha(&p2);

InicializaPilha(&p3);

for (i=0; i<TAM; i++)

{

printf("Digite o %dº elemento:\n", i+1);

scanf("%f", &n);

Empilha(&p1, n);

}

for (i=0; i<TAM; i++)

{

p2.pilha[i] = p1.pilha[i];

p3.pilha[i] = p2.pilha[i];

}

for (i=0; i<TAM; i++)

{

printf("%f\t", p3.pilha[i]);

}

return 0;

}

Exercício 07

#include <stdio.h>

#define TAM 30

struct tfila

{

int F, R;

int fila[TAM];

};

void inicializaFila(struct tfila *pf)

{

pf -> F = 0;

pf -> R = -1;

}

int filaVazia(struct tfila *pf)

{

if (pf -> F > pf -> R)

return 1;

return 0;

}

int filaCheia(struct tfila *pf)

{

if (pf -> R == TAM-1)

return 1;

return 0;

}

int insereFila(struct tfila *pf, int valor)

{

if (filaCheia(pf))

return 0;

pf -> fila[++pf -> R] = valor;

return 1;

}

int removeFila(struct tfila *pf)

{

int y;

if (filaVazia(pf))

return 0;

y = pf -> fila[pf -> F++];

return y;

}

struct tpilha

{ int topo;

int pilha[TAM];

};

void InicializaPilha(struct tpilha *ps)

{

ps -> topo = -1;

}

int PilhaVazia(struct tpilha *ps)

{

if (ps -> topo == -1)

return 1;

return 0;

}

int PilhaCheia(struct tpilha *ps)

{

if (ps -> topo == TAM-1)

...

Baixar como (para membros premium)  txt (12.6 Kb)   pdf (56.7 Kb)   docx (19.9 Kb)  
Continuar por mais 13 páginas »
Disponível apenas no TrabalhosGratuitos.com