#include <stdio.h>
#include <stdlib.h>
struct Pilha {
int topo;
int capa;
float *pElem;
};
void criarpilha(struct Pilha *p, int c) {
p->topo = -1;
p->capa = c;
p
->pElem
= (float *) malloc(c
* sizeof(float));}
void push(struct Pilha *p, float v) {
p->topo++;
p->pElem[p->topo] = v;
}
float sub(struct Pilha *p) {
int x, y;
float calc;
p->topo--;
x = p->pElem[p->topo];
p->topo++;
y = p->pElem[p->topo];
calc = x - y;
p->topo--;
p->pElem[p->topo] = calc;
return calc;
}
float mpy(struct Pilha *p) {
int x, y;
float calc;
p->topo--;
x = p->pElem[p->topo];
p->topo++;
y = p->pElem[p->topo];
calc = x * y;
p->topo--;
p->pElem[p->topo] = calc;
return calc;
}
float add(struct Pilha *p) {
int x, y;
float calc;
p->topo--;
x = p->pElem[p->topo];
p->topo++;
y = p->pElem[p->topo];
calc = x + y;
p->topo--;
p->pElem[p->topo] = calc;
return calc;
}
float Div(struct Pilha *p) {
int x, y;
float calc;
p->topo--;
x = p->pElem[p->topo];
p->topo++;
y = p->pElem[p->topo];
calc = x / y;
p->topo--;
p->pElem[p->topo] = calc;
return calc;
}
float dec(struct Pilha *p) {
int x;
p->pElem[p->topo]--;
return p->pElem[p->topo];
}
float pop(struct Pilha *p) {
float aux = p->pElem[p->topo];
p->topo--;
return aux;
}
float monstrarpilha(struct Pilha *p) {
return p->pElem[p->topo];
}
int main() {
struct Pilha p;
int capacidade = 4;
int A = 9, B = 3, C = 2, D = 1, E = 1;
criarpilha(&p, capacidade);
push(&p, A);
printf("\nPUSH A: %.1f\n", monstrarpilha
(&p
));
push(&p, B);
printf("\nPUSH B: %.1f\n", monstrarpilha
(&p
));
printf("\nSubtracao: %.1f\n", sub
(&p
));
push(&p, C);
printf("\nPUSH C: %.1f\n", monstrarpilha
(&p
));
push(&p, D);
printf("\nPUSH D: %.1f\n", monstrarpilha
(&p
));
push(&p, E);
printf("\nPUSH E: %.1f\n", monstrarpilha
(&p
));
printf("\nmultiplicacao: %.1f\n", mpy
(&p
)); printf("\nadicao: %.1f\n", add
(&p
)); printf("\ndecrementar: %.1f\n", dec
(&p
)); printf("\ndivisao: %.1f\n", Div
(&p
));
printf("\nPOP F%.1f\n", pop
(&p
));
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCgpzdHJ1Y3QgUGlsaGEgewogICAgaW50IHRvcG87CiAgICBpbnQgY2FwYTsKICAgIGZsb2F0ICpwRWxlbTsKfTsKCnZvaWQgY3JpYXJwaWxoYShzdHJ1Y3QgUGlsaGEgKnAsIGludCBjKSB7CiAgICBwLT50b3BvID0gLTE7CiAgICBwLT5jYXBhID0gYzsKICAgIHAtPnBFbGVtID0gKGZsb2F0ICopIG1hbGxvYyhjICogc2l6ZW9mKGZsb2F0KSk7Cn0KCgp2b2lkIHB1c2goc3RydWN0IFBpbGhhICpwLCBmbG9hdCB2KSB7CiAgICBwLT50b3BvKys7CiAgICBwLT5wRWxlbVtwLT50b3BvXSA9IHY7Cn0KCmZsb2F0IHN1YihzdHJ1Y3QgUGlsaGEgKnApIHsKICAgIGludCB4LCB5OwogICAgZmxvYXQgY2FsYzsKICAgIHAtPnRvcG8tLTsKICAgIHggPSBwLT5wRWxlbVtwLT50b3BvXTsKICAgIHAtPnRvcG8rKzsKICAgIHkgPSBwLT5wRWxlbVtwLT50b3BvXTsKICAgIGNhbGMgPSB4IC0geTsKICAgIHAtPnRvcG8tLTsKICAgIHAtPnBFbGVtW3AtPnRvcG9dID0gY2FsYzsKCiAgICByZXR1cm4gY2FsYzsKfQoKZmxvYXQgbXB5KHN0cnVjdCBQaWxoYSAqcCkgewogICAgaW50IHgsIHk7CiAgICBmbG9hdCBjYWxjOwogICAgcC0+dG9wby0tOwogICAgeCA9IHAtPnBFbGVtW3AtPnRvcG9dOwogICAgcC0+dG9wbysrOwogICAgeSA9IHAtPnBFbGVtW3AtPnRvcG9dOwoKICAgIGNhbGMgPSB4ICogeTsKCiAgICBwLT50b3BvLS07CiAgIC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