Sunday, July 16, 2006

How easy to delete the linked list in c++

typedef struct _tagLinkedList
{
_tagLinkedList *pNextLink;
int m_iData;
_tagLinkedList()
{
pNextLink = NULL;

}

~_tagLinkedList()
{
if (pNextLink )
delete pNextLink;
pNextLink = NULL

}
}sLinkedList;

2 comments:

Anonymous said...

May be it should have some member functions to add a node to the list. Normally I would prefer to use list STL, because that avoids handling memory hassles and is more generic.

Vipin

FarPointer said...

Yes to make it an ADT we need to add many member functions , this is just an example to show the proper use of the structures destructor.