Hello,
I'm trying to write a linked list in C++ and I'm having a bit of trouble. I understand the absolute basics of a list (front/back insertion, destructor) but I'm having a bit of trouble putting my ideas into code. Lets see if I can show what I have so far:
Code:
struct Node
{
int data;
Node* nextPtr;
};
class LinkedList
{
public:
LinkedList() : nodePtr(0) { }
~LinkedList();
private:
Node* nodePtr;
};
LinkedList::~LinkedList()
{
Node* tmpPtr;
while(nodePtr->nextPtr != 0)
{
tmpPtr = nodePtr;
nodePtr = nodePtr->next;
delete nodePtr;
}
}
2 questions:
1.) Does my constructor basically do the following?
Code:
Node * bla;
bla->data = 0;
bla->nextPtr = 0;
2.) Am I on basically the right track?
Please try not to "give it all away" so to speak, if necessary try to push me slightly in the right direction. This is my first time trying to write a List class from scratch and I feel like theres lots to learn.
Thanks.