/*-----------------------------------------------------------------------
	File:  stkitest.c
	Author:  M. Sebern
	Date:  19-May-1995
	Purpose:
		Test the operation of the stack ADT routines.
	Revision history:
		Jeffrey Blessing 3-13-98 for CS-481 students.
-----------------------------------------------------------------------*/

/* Include Files: */

#include <stdio.h>
#include <stdlib.h>
#include "stackint.h"

/* Constant Definitions: */

/* Macro Definitions: */

/* Type Declarations: */

/* Function Prototypes: */

/* External Variables: */

/*-----------------------------------------------------------------------
	Function:	main
	Purpose:
		Main line routine of ADT test program.
	Usage:
		Called from operating system at program start.
	Input Parameters:
		None.
	Output Parameters:
		Return value:	Operating system status.
	Side Effects:
		None.
	Functions Referenced:

	CreateStack	Create a stack instance of specified max size.
	DestroyStack	Destroy a stack instance and free its memory.
	IsStackEmpty	Test if a stack is empty.
	PopStack	Pop an element off the top of a stack.
	PushStack	Push an element onto a stack.
	TopStack	Get a copy of the top stack element.

	Pseudo Code:
		Create two stack instances.
		Test if stack 1 is empty.
		Push a number of values onto stack 1.
		Print top element of stack 1.
		Transfer stack 1 contents to stack 2.
		Empty and print contents of stack 2.
		Add a single element to stack 2.
		Destroy all stack instances.
		Return "success".
-----------------------------------------------------------------------*/

int main (void)
{
	Stack	stack1;
	Stack	stack2;
	int	ii;
	int	elem;

	stack1 = CreateStack();
	stack2 = CreateStack();

	if ( IsStackEmpty(stack1) ) printf("Stack 1 is empty.\n");

	for (ii = 1; ii <= 12; ii++) PushStack(stack1, ii);
	printf ("Current top of stack 1 is [%d].\n",
		TopStack(stack1) );

	while ( !IsStackEmpty(stack1) )
	{
	    elem = PopStack(stack1);
	    printf("Moving element [%d] to stack 2\n", elem);
	    PushStack(stack2, elem);
	}

	/* Uncomment to test stack underflow. */
/*
	elem = PopStack(stack1);
*/

	/* Uncomment to test stack overflow. */
/*
	for (;;) PushStack(stack1,0);
*/

	while ( !IsStackEmpty(stack2) )
	{
	    elem = PopStack (stack2);
	    printf("Removed element [%d] from stack 2.\n", elem);
	}

	PushStack(stack2, 999);

	DestroyStack(stack1);
	DestroyStack(stack2);

	return 0;	/* Return success */
}
