// ListAr.cpp
#include "ListAr.h"
#include "Exception.h"
#include <stdlib.h>

static const int LIST_SIZE = 3;

// Add one with wraparound
template <class Etype>
void List<Etype>::increment( int & X ) const
{
    if( ++X == maxSize )
        X = 0;
}

// constructor.  initializes currentSize to 0, front to index 0,
// and back to index -1
template <class Etype>
List<Etype>::List( ) : maxSize( LIST_SIZE ),
                         currentSize( 0 ), front( 0 ), back( -1 )
{
}


template <class Etype>
const List<Etype> &
List<Etype>::operator=( const List<Etype> & Rhs )
{
    if( this == &Rhs )
        return Rhs;

    VecList = Rhs.VecList;
    currentSize = Rhs.currentSize;
    maxSize = Rhs.maxSize;
    front = 0;
    back = CurrentSize - 1;
    return *this;
}

template <class Etype>
void List<Etype>::doubleList( void )
{
    front = 0;
    back = currentSize - 1;
    maxSize *= 2;
    VecList.Resize( maxSize );
}
    
template <class Etype>
void List<Etype>::add( const Etype & X )
{
    if( currentSize == maxSize )
        doubleList( );

    increment( back );
    VecList[ back ] = X;
    currentSize++;
}

template <class Etype>
void List<Etype>::remove( void )
{
    EXCEPTION( isEmpty( ), "List is empty" );
    currentSize--;
    increment( front );
}

template <class Etype>
const Etype & List<Etype>::getFront( ) const
{
    EXCEPTION( isEmpty( ), "List is empty" );
    return VecList[ front ];
}

template <class Etype>
int List<Etype>::sizeOf( )
{
   return currentSize;
}

template <class Etype>
ostream &operator << ( ostream & out, List<Etype> &passQue )
{
   passQue.print( out );
   return out;
}

template <class Etype>
ostream &List<Etype>:: print( ostream &out )
{
   int listSize = sizeOf();
   for ( int i = 0; i < listSize; i++ )
      out << VecList[i] << endl;
   return out;
}
   