Good eye. I made 2 updates (constructor, deletion of tempPtr in destructor) and to me it looks OK. I can't compile this yet or even spend more than 5 minutes working on it ATM because I'm also trying to do some C++ homework right now. I should be done in an hour or so, and if my constructor/destructor look good then I'm going to write the appendHead and appendTail member functions.
Code:
struct Node
{
int data;
Node* nextPtr;
};
class LinkedList
{
public:
LinkedList() : nodePtr->nextPtr(0) { }
~LinkedList();
private:
Node* nodePtr;
};
LinkedList::~LinkedList()
{
Node* tmpPtr;
while(nodePtr->nextPtr != 0)
{
tmpPtr = nodePtr;
nodePtr = nodePtr->nextPtr;
delete tmpPtr;
}
}
Does that look better? I basically made a typo in the destructor the first time, if my destructor's right then that's what I was trying to do all along... I gotta watch out for those typing errors. And can I use the arrow operator in the member initializer list of the constructor like I'm doing? I don't really think that any data should be filled in to the first node, I'm thinking right now that I will use that as a head node - a pointer to the first element in the List, instead of it being the first node in the List.
Thanks for your help.