#include #include "list.h" IntList::IntList() : size( 0 ) , cursor( 0 ) {} bool IntList::isEmpty() { return getSize() == 0; } bool IntList::isFull() { return getSize() == MAX_LIST_LENGTH; } int IntList::getSize() { assert( size >= 0 && size <= MAX_LIST_LENGTH ); return size; } void IntList::start() { cursor = 0; } void IntList::advance() { assert( !atEnd() ); cursor++; } bool IntList::atEnd() { return cursor >= size; } int IntList::getData() { assert( cursor >= 0 && cursor < size ); return items[ cursor ]; } void IntList::insertBefore( int item ) { if( isEmpty() ) { placeAtStart( item ); } else { assert( cursor >= 0 && cursor < size ); makeRoom( cursor ); items[ cursor ] = item; } } void IntList::insertAfter( int item ) { if( isEmpty() ) { placeAtStart( item ); } else { assert( cursor >= 0 && cursor < size ); makeRoom( cursor + 1 ); items[ cursor + 1 ] = item; ++cursor; } } void IntList::deleteItem() { assert( cursor >= 0 && cursor < size ); for( int idx = cursor; idx < size; idx++ ) { items[ idx ] = items[ idx + 1 ]; } --size; } void IntList::makeRoom( int position ) { assert( !isFull() ); for( int idx = size - 1; idx >= position; --idx ) { items[ idx + 1 ] = items[ idx ]; } ++size; } void IntList::placeAtStart( int item ) { cursor = 0; items[ 0 ] = item; size = 1; }