#include <stdio.h>
#include <stdlib.h>
#define MAX 10
typedef struct pilha {
int qnt;
int dados[MAX];
} Pilha;
Pilha* cria() {
Pilha
*p
= malloc(sizeof(Pilha
)); if (p != NULL) {
p->qnt = 0;
}
return p;
}
void insere(Pilha *p, int valor) {
p->dados[p->qnt] = valor;
p->qnt++;
}
void exibe(Pilha *p) {
for (int i = 0; i < p->qnt; i++)
}
Pilha* inverte(Pilha *p) {
Pilha *outra = cria();
while (p->qnt > 0) {
outra->dados[outra->qnt] = p->dados[p->qnt - 1];
p->qnt--;
outra->qnt++;
}
return outra;
}
int main() {
Pilha *p = cria();
insere(p, 32);
insere(p, 45);
insere(p, 78);
exibe(p);
p = inverte(p);
exibe(p);
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCiNkZWZpbmUgTUFYIDEwCgp0eXBlZGVmIHN0cnVjdCBwaWxoYSB7CiAgICBpbnQgcW50OwogICAgaW50IGRhZG9zW01BWF07Cn0gUGlsaGE7ClBpbGhhKiBjcmlhKCkgewogICAgUGlsaGEgKnAgPSBtYWxsb2Moc2l6ZW9mKFBpbGhhKSk7CiAgICBpZiAocCAhPSBOVUxMKSB7CiAgICAgICAgcC0+cW50ID0gMDsKICAgIH0KICAgIHJldHVybiBwOwp9CnZvaWQgaW5zZXJlKFBpbGhhICpwLCBpbnQgdmFsb3IpIHsKICAgIHAtPmRhZG9zW3AtPnFudF0gPSB2YWxvcjsKICAgIHAtPnFudCsrOwp9CnZvaWQgZXhpYmUoUGlsaGEgKnApIHsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgcC0+cW50OyBpKyspCiAgICAgICAgcHJpbnRmKCIlM2QiLCBwLT5kYWRvc1tpXSk7Cn0KUGlsaGEqIGludmVydGUoUGlsaGEgKnApIHsKICAgIFBpbGhhICpvdXRyYSA9IGNyaWEoKTsKICAgIHdoaWxlIChwLT5xbnQgPiAwKSB7CiAgICAgICAgb3V0cmEtPmRhZG9zW291dHJhLT5xbnRdID0gcC0+ZGFkb3NbcC0+cW50IC0gMV07CiAgICAgICAgcC0+cW50LS07CiAgICAgICAgb3V0cmEtPnFudCsrOwogICAgfQogICAgcmV0dXJuIG91dHJhOwp9CmludCBtYWluKCkgewogICAgUGlsaGEgKnAgPSBjcmlhKCk7CiAgICBpbnNlcmUocCwgMzIpOwogICAgaW5zZXJlKHAsIDQ1KTsKICAgIGluc2VyZShwLCA3OCk7CiAgICBleGliZShwKTsKICAgIHAgPSBpbnZlcnRlKHApOwogICAgcHJpbnRmKCJcbiIpOwogICAgZXhpYmUocCk7Cn0=