View Single Post
Old 01-31-2005, 02:26 PM   #6 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
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;
    }
}

//------------------------------------------}
__________________
Valmont is offline   Reply With Quote