#ifndef lint
static char *sccsid = "@(#)indexlist.c	1.3 (Steve Hill) 5/23/90";
#endif

/* indexlist.c
 *
 * Routines to create and manipulate lists of real numbers.
 */

#include <stdio.h>


#include "basetype.h"
#include "malloc.h"
#include "indexlist.h"

static
index_list_t *
IndexList(index, ptr)
real_t		index;
index_list_t	*ptr;
{
	index_list_t	*list;

	list = (index_list_t *) malloc(sizeof(index_list_t));
	if (list == IndexListNull)
		FatalError(__FILE__, __LINE__, "IndexList: out of memory");

	list->index = index;
	list->ptr   = ptr;

	return(list);
}

index_list_t *
IndexListPush(index, list)
real_t		index;
index_list_t	*list;
{
	index_list_t	*new;

	new = IndexList(index, list);
	return(new);
}

index_list_t *
IndexListPop(list)
index_list_t	*list;
{
	index_list_t	*next;

	if (list == IndexListNull)
		return(IndexListNull);

	next = list->ptr;
	free((char *) list);
	return(next);
}

real_t
IndexListTop(list)
index_list_t	*list;
{
	if (list == IndexListNull)
		return(REAL_ONE);

	return(list->index);
}

index_list_t *
IndexListCopy(list)
index_list_t	*list;
{
	if (list != IndexListNull)
		return(IndexListPush(list->index, IndexListCopy(list->ptr)));
	else
		return(IndexListNull);
}

void
IndexListFree(list)
index_list_t	*list;
{
	while (list != IndexListNull)
		list = IndexListPop(list);
}
