#include <stdlib.h>

#include "list.h"

IntItem *
cons (int num, IntItem *tail)
{
  IntItem *cell = malloc (sizeof (IntItem));
  cell->num = num;
  cell->tail = tail;
  return cell;
}

void
freeList (IntItem *list)
{
  while (list != NULL)
    {
      IntItem *tmp = list;
      list = list->tail;
      free (tmp);
    }
}

int
sumList (IntItem *list)
{
  int sum = 0;
  while (list != NULL)
    {
      sum += list->num;
      list = list->tail;
    }
  return sum;
}