Implémentation d'une pile impérative avec une liste en C

/* implementation of the stack abstract data type (imperative interface)
   using a list concrete data type */

#include 
#include 
#include "stack.h"
#include "list.h"

struct stack
{
  list contents;
};

stack
stack_create(void)
{
  stack temp = malloc(sizeof(struct stack));
  temp -> contents = NULL;
  return temp;
}

void
stack_push(stack s, void *object)
{
  s -> contents = cons(object, s -> contents);
}

int
stack_empty(stack s)
{
  return s -> contents == NULL;
}

void *
stack_top(stack s)
{
  assert(!stack_empty(s));
  return s -> contents -> head;
}

void
stack_pop(stack s)
{
  assert(!stack_empty(s));
  s -> contents = tail_and_free(s -> contents);
}