CObList::InsertBefore

Syntax

POSITION InsertBefore( POSITION position, CObject* newElement )
throw ( CMemoryException );

Parameters

position

A POSITION value returned by a previous GetNext, GetPrev, or Find member function call.

newElement

The object pointer to be added to this list.

Remarks

Adds an element to this list 'before' the element at the specified position.

Return Value

A POSITION value that can be used for iteration or object pointer retrieval; NULL if the list is empty.

Example

CObList list;

POSITION pos1, pos2;

list.AddHead( new CAge( 21 ) );

list.AddHead( new CAge( 40 ) ); // List now contains (40, 21)

if( ( pos1 = list.GetTailPosition() ) != NULL )

{

pos2 = list.InsertBefore( pos1, new CAge( 65 ) );

}

#ifdef _DEBUG

afxDump.SetDepth( 1 );

afxDump << "InsertBefore example: " << &list << "\\n";

#endif

The results from this program are as follows:

InsertBefore example: A CObList with 3 elements

a CAge at $4AE2 40

a CAge at $4B02 65

a CAge at $49E6 21

See Also

CObList::Find, CObList::InsertAfter