Let's try to be as object oriented as we can be. The struct leaves us with access to its public members. Encapsulate the struct as well. And there is no need to initialize the the nodePointer or the nextPointer:
Code:
class LinkedList
{
public:
LinkedList();
~LinkedList();
private:
struct Node
{
int data;
Node* nextPtr;
};
Node* nodePtr;
};
//-----------------------------------------
LinkedList::LinkedList() : nodePtr(0)
{}
//------------------------------------------
LinkedList::~LinkedList()
{
while(nodePtr->nextPtr != 0)
{
Node* tmpPtr = nodePtr;
nodePtr = nodePtr->nextPtr;
delete tmpPtr;
}
}
//------------------------------------------}