/* This program uses code from "Algorithms in C, Third Edition,"
 *               by Robert Sedgewick, Addison-Wesley, 1998.
 */

#include <stdlib.h>
#include <stdio.h>

#include "list_interface.h"


main()
{
   /* our list must be initialized to NULL, until we have the first
    * link created. Then, our list will simply be set equal to that 
    * first link.
    */
   list the_list = newList();

   link current_link = NULL;
   while(1)
   {
      int number;
      printf("please enter an integer: ");
      int items_read = scanf("%d", &number);
      if (items_read != 1)
      {
         break;
      }
     
      /* allocate memory for the next link */
      link next_item = newLink(number);
      insertLink(the_list, current_link, next_item);
      current_link = next_item;
   }
   
   printList(the_list);
   int length = listLength(the_list);
   printf("the length of the list is %d.\n", length);
   
   destroyList(the_list);
   return 0;
}
