Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- //definir o tamanho da pilha(quantidade de dados)
- #define tamanho 8
- struct tipo_ra{
- int dados[tamanho];
- int ini;
- int topo;
- };
- tipo_ra identifica;
- void push(int elemento){
- if(identifica.topo == tamanho){
- printf("Fila cheia.\n");
- system("pause");
- }
- else
- {
- identifica.dados[identifica.topo] = elemento;
- identifica.topo++;
- }
- }
- int pop(){
- int elemento;
- if(identifica.topo == identifica.ini){
- printf("Fila vazia.\n");
- system("pause");
- }
- else
- {
- identifica.topo--;
- elemento = identifica.dados[identifica.topo];
- return elemento;
- }
- }
- int main(){
- identifica.topo = 0;
- identifica.ini = 0;
- int aux;
- printf("\n Disciplina: Estrutura de Dados I\n Material de Avaliação Prática de Aprendizagem - MAPA\n Aluno: Jonathas Ferreira de Oliveira Aquino\n");
- system("pause");
- //empilhando RA
- printf("\n Empilhando RA...\n\n");
- printf(" 1 7 2 7 2 7 1 5\n\n");
- //empilha RA
- push(1);
- push(7);
- push(2);
- push(7);
- push(2);
- push(7);
- push(1);
- push(5);
- system("pause");
- //desempilhando RA
- printf("\n Desempilhando RA... \n\n");
- printf(" %d ", pop());
- printf("%d ", pop());
- printf("%d ", pop());
- printf("%d ", pop());
- printf("%d ", pop());
- printf("%d ", pop());
- printf("%d ", pop());
- printf("%d ", pop());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement