generated from maria-larissa/Mini-projetos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblema4.c
55 lines (51 loc) · 1.04 KB
/
Problema4.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <stdlib.h>
#define max 100 //Tamanho máximo de elementos
/*
Struct que define os campos de cada elemento da pilha.
*/
typedef struct elemento{
int valor;
int pos;
}Elemento;
/*
Struct que define os da pilha.
*/
typedef struct pilha
{
Elemento vetor[max];
int quant;
}Pilha;
/*
Função para cria uma pilha dinâmicamente.
*/
Pilha *criar_pilha(int tam){
Pilha *pi = (Pilha*)malloc(tam*sizeof(Elemento));
printf("\nPreencha a pilha");
int i=tam;
while(i>0){
printf("\nposição[%d]: ", i);
scanf("%d", &(*pi).vetor[i]);
(*pi).quant++;
i--;
}
return pi;
}
/*
Caso queira testar, basta decomentar o código a seguir
e executar o arquivo.
*/
int main(){
int i=1, tam;
printf("Digite o tamanho da pilha: ");
scanf("%d", &tam);
Pilha *pi = criar_pilha(tam);
printf("\n\tPILHA");
while(i<=tam){
printf("\nposição[%d]= %d ", i, (*pi).vetor[i]);
i++;
}
printf("\n");
return 0;
}
// */