This topic has not yet been rated - Rate this topic

CObList::InsertBefore

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

POSITION InsertBefore(
   POSITION position,
   CObject* newElement 
);
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.

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

The following table shows other member functions that are similar to CObList::InsertBefore.

Class

Member Function

CPtrList

POSITION InsertBefore( POSITION position , void* newElement );

CStringList

POSITION InsertBefore( POSITION position , const CString& newElement );

POSITION InsertBefore( POSITION position , LPCTSTR newElement );

See CObList::CObList for a listing of the CAge class.


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 << _T("InsertBefore example: ") << &list << _T("\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

Header: afxcoll.h

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ