/*
 * test_tree.c
 * This program tests the doubly-linked list package.
 */
#include <stdio.h>
#include "list.h"

int main ()
{
  List        *p_list;
  Element     *p_elem;

  /* Initialize a list an insert several numbers to it. */
  p_list = list_init();
  list_append (p_list, 3);
  list_append (p_list, 4);
  list_append (p_list, 5);
  list_prepend (p_list, 2);
  list_prepend (p_list, 1);
  list_append (p_list, 6);
  list_append (p_list, 7);
  list_delete (p_list, 6);     /* Test the delete function. */

  /* Try to find several values. */
  if (list_find (p_list, 3))
    printf ("%g is found in the list.\n", 3);
  else
    printf ("%g is not found in the list.\n", 3);

  if (list_find (p_list, 3.2))
    printf ("%g is found in the list.\n", 3.2);
  else
    printf ("%g is not found in the list.\n", 3.2);

  /* Print the content of the list. */
  p_elem = p_list->p_head;
  while (p_elem != NULL)
  {
    printf ("%g ", p_elem->value);
    p_elem = p_elem->p_next;
  }
  printf ("\n");
  printf ("%d elements in the list.\n", p_list->size);

  /* Test the pop functions. */
  printf ("Popped %g.\n", list_pop_first(p_list));
  printf ("Ejected %g.\n", list_pop_last(p_list));

  /* Print the reversed list. */
  for (p_elem = p_list->p_tail; 
       p_elem != NULL;
       p_elem = p_elem->p_prev)
  {
    printf ("%g ", p_elem->value);
  }
  printf ("\n");
  printf ("%d elements in the list.\n", p_list->size);

  /* Free memory. */
  list_reset (p_list);
  free (p_list);

  return (0);
}

