/*-----------------------------------------------------------------------
	File:  stkitst2.cpp
	Author:  M. Sebern
	Date:  23-May-1995
	Purpose:
		Test the operation of the C++ stack ADT routines,
		with constructor/destructor.
	Revision history:
		Jeffrey Blessing 3-13-98 for CS-481 students.
-----------------------------------------------------------------------*/

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

/*-----------------------------------------------------------------------
	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.
	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.
		Free all stack instance data.
		Return "success".
-----------------------------------------------------------------------*/

int main(void)
{
	Stack	stack1;	// Initialized by constructor.
	int		ii;
	int		elem;

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

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

	Stack	stack2;  // Unlike C, we can declare here.

	while ( !stack1.IsEmpty() )
	{
	    elem = stack1.Pop();
	    printf("Moving element [%d] to stack 2\n", elem);
	    stack2.Push(elem);
	}

	// Uncomment to test invalid "private" member access.
//	stack1.current_elem = 0;

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

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

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

	stack2.Push(999);

	// Stack instance data will be freed by destructor when
	// stacks go out of scope.

	return 0;	/* Return success */
}
