#include<stdio.h>
#include<stdlib.h>
struct data {
char key;
struct data *next;
};
void push(struct data **top, char key);
char pop(struct data **top);
void print_stack_list(struct data *top);
int main() {
struct data *top;
top = NULL;
push(&top, 'a');
print_stack_list(top);
push(&top, 'b');
print_stack_list(top);
pop(&top);
print_stack_list(top);
pop(&top);
return 0;
}
void push(struct data **top, char key) {
struct data *d;
d
= (struct data
*) malloc(sizeof(struct data
)); d->key = key;
d->next = *top;
*top = d;
}
char pop(struct data **top) {
int key;
struct data *d;
key = (*top)->key;
d = *top;
*top = (*top)->next;
return key;
}
void print_stack_list(struct data *top) {
while (top != NULL) {
top = top->next;
}
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RkbGliLmg+CgpzdHJ1Y3QgZGF0YSB7CiAgY2hhciBrZXk7CiAgc3RydWN0IGRhdGEgKm5leHQ7Cn07Cgp2b2lkIHB1c2goc3RydWN0IGRhdGEgKip0b3AsIGNoYXIga2V5KTsKY2hhciBwb3Aoc3RydWN0IGRhdGEgKip0b3ApOwp2b2lkIHByaW50X3N0YWNrX2xpc3Qoc3RydWN0IGRhdGEgKnRvcCk7CiAKaW50IG1haW4oKSB7CiAgc3RydWN0IGRhdGEgKnRvcDsKICB0b3AgPSBOVUxMOwoKICBwdXNoKCZ0b3AsICdhJyk7CiAgCiAgcHJpbnRfc3RhY2tfbGlzdCh0b3ApOwogIHByaW50ZigiXG4iKTsKCiAgcHVzaCgmdG9wLCAnYicpOwoKICBwcmludF9zdGFja19saXN0KHRvcCk7CiAgcHJpbnRmKCJcbiIpOwoKICBwb3AoJnRvcCk7CgogIHByaW50X3N0YWNrX2xpc3QodG9wKTsKICBwcmludGYoIlxuIik7CgogIHBvcCgmdG9wKTsKCiAgcmV0dXJuIDA7Cn0KCnZvaWQgcHVzaChzdHJ1Y3QgZGF0YSAqKnRvcCwgY2hhciBrZXkpIHsKICBzdHJ1Y3QgZGF0YSAqZDsKICBkID0gKHN0cnVjdCBkYXRhICopIG1hbGxvY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