#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);
  printf("\n");

  push(&top, 'b');

  print_stack_list(top);
  printf("\n");

  pop(&top);

  print_stack_list(top);
  printf("\n");

  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;
  free(d);
  return key;
}

void print_stack_list(struct data *top) {
  while (top != NULL) {
    printf("%c\n",top->key);
    top = top->next;
  }
}