OK I had a few errors still, I think I'm bug free now
I got the following code working, too bad I have to go to class now. (I forgot to allocate a new node... duh...)
Code:
#ifndef LIST_H_
#define LIST_H_
#include <iostream>
using namespace std;
struct Node
{
int data;
Node* nextPtr;
};
class LinkedList
{
public:
LinkedList()
{
nodePtr = new Node;
nodePtr->nextPtr = 0;
}
~LinkedList();
private:
Node* nodePtr;
};
LinkedList::~LinkedList()
{
while(nodePtr->nextPtr != 0)
{
Node* tmpPtr = nodePtr;
nodePtr = nodePtr->nextPtr;
delete tmpPtr;
}
}
#endif
and main
Code:
#include <iostream>
using namespace std;
#include "List.h"
int main()
{
LinkedList test;
return 0;
}
I'll probably keep having to modify it as I add features to the class, but thats the goal, is for me to learn lists. I have drawn a few out on paper which I recommend to people just learning, it really helps to visualize the list. Anyways hopefully I'll add some functionality to this class tonite, or maybe even after class today. We'll see. I'll keep you guys updated.