#include<stdio.h>
#include<stdlib.h>
struct data{
char key;
struct data *next;
};
void print_stack_list(struct data *top) {
while (top != 0) {
printf("key: %c, next: %p\n", top->key, (void *)top->next);
top = top->next;
}
}
void release(struct data *top) {
struct data *p;
while (top != 0) {
p = top->next;
free(top);
top = p;
}
}
int main() {
struct data *top, *cur;
char c;
top = 0;
c = 'a';
while (c <= 'd') {
if ((cur = malloc(sizeof(struct data))) == 0) {
fprintf(stderr, "cannnot allocate enough memory, aborted.\n");
return 0;
}
cur->key = c;
cur->next = top;
top = cur;
c++;
}
print_stack_list(top);
release(top);
return 0;
}
/* end */