operation on arrayvoid arrayadd objectamp toadd


Operation on array:

void Array::add( Object& toAdd )

{

    lastElementIndex++;

    while( ptrAt( lastElementIndex ) != ZERO &&

           lastElementIndex <= upperbound

         )

        lastElementIndex++;

 

    if( lastElementIndex > upperbound )

        reallocate( lastElementIndex - lowerbound + 1 );

 

    setData( lastElementIndex, &toAdd );

    itemsInContainer++;

    CHECK( itemsInContainer > 0 );

}

 

void Array::addAt( Object& toAdd, int atIndex )

{

    PRECONDITION( atIndex >= lowerbound );

    if( atIndex > upperbound )

        reallocate( atIndex - lowerbound + 1 );

 

    if( ptrAt( atIndex ) != ZERO )

        {

        delete ptrAt( atIndex );

        }

 

    setData( atIndex, &toAdd );

}

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: operation on arrayvoid arrayadd objectamp toadd
Reference No:- TGS0174758

Expected delivery within 24 Hours