class xyz { public : xyz *GetNextItem() { return next ; } xyz *GetPrevItem() { return prev ; } void InsertAfter( xyz *NewItem ) // Insert NewItem after this item in list { NewItem->prev = this ; // item prior to NewItem will be this one NewItem->next = next ; // item next to NewItem will be the one currently next to this one if ( next != NULL ) // if not last item in list next->prev = NewItem ; // next in list wants to point back to new item next = NewItem ; // next item to this will be the NewItem } void RemoveFromList() // Remove this item from the list it is in { // CAREFUL USING THIS - MAY CAUSE MEMORY LEAK IF NO POINTER TO THE ITEM AFTER REMOVED if ( next != NULL ) // if not last item in list next->prev = prev ; // item before next in list will be the one prior to this one if ( prev != NULL ) // if not first item in list prev->next = next ; // item after previous in list will be the one next to this one next = NULL ; // set pointers of this item to NULL prev = NULL ; } xyz *RemovePreviousItem() // Remove previous item in list, returning a pointer to it { xyz *RemovedItem = prev ; // save pointer to previous item in list if ( prev != NULL ) // if there is an item prev->RemoveFromList() ; // get it to remove itself from the list return RemovedItem ; // return pointer to removed item } private : xyz *next ; xyz *prev ; }