void Array::addAt( Object& toAdd, int atIndex )
{
    PRECONDITION( atIndex >= lowerbound );
    if( atIndex > upperbound )
        reallocate( atIndex - lowerbound + 1 );

    if( ptrAt( atIndex ) != ZERO )
        {
        if( ownsElements() )
            delete ptrAt( atIndex );
        itemsInContainer--;
        }

    setData( atIndex, &toAdd );
    itemsInContainer++;
    CHECK( itemsInContainer > 0 );
}
void SortedArray::detach( Object& toDetach, DeleteType dt )
{
    int detachPoint = find( toDetach );
    if( detachPoint != INT_MIN )
        {
        if( delObj(dt) )
            delete ptrAt( detachPoint );
        removeEntry( detachPoint );
        itemsInContainer--;
        if( detachPoint <= lastElementIndex )
            lastElementIndex--;
        }
}
void Array::add( Object& toAdd )
{
    lastElementIndex++;
    while( lastElementIndex <= upperbound &&
           ptrAt( lastElementIndex ) != ZERO
         )
        lastElementIndex++;

    if( lastElementIndex > upperbound )
        reallocate( lastElementIndex - lowerbound + 1 );

    setData( lastElementIndex, &toAdd );
    itemsInContainer++;
    CHECK( itemsInContainer > 0 );
}