/* File: cityStk.c
 * Desc: Implementation of cityStk library
 * The cityStk library implements a stack (ie a last-in, first out list)
 * of pairs of cities (to, from).
 * Anthony Towns
 * 15 August 1997
 */

#include "citystk.h"
#include <assert.h>

void newStack( stack *s )
{
     s->nElems = 0;

#ifdef DEBUG
     {
	  /* We initialize all elements to NoCity |--> NoCity for your
	   * debugging pleasure!
	   */

	  int i;
	  cityPair zippo = { NoCity, NoCity };

	  for ( i = 0; i < MAX_N_CITYPAIRS; i++ ) s->elem[i] = zippo;
     }
#endif
}

void push( stack *s, cityPair c )
{
     assert( s->nElems < MAX_N_CITYPAIRS );

     s->elem[s->nElems++] = c;
}

void pop( stack *s, cityPair *c )
{
     assert( s->nElems > 0 );

     *c = s->elem[--s->nElems];

#ifdef DEBUG
     {
	  /* Mark the just popped value as NoCity |--> NoCity to make
	   * life funkier. */

	  cityPair zippo = { NoCity, NoCity };
	  s->elem[s->nElems] = zippo;
     }
#endif

}

bool isEmpty( stack s )
{
     return s.nElems == 0;
}


