im just reviewing my code now and it looks like one biggg mess....
and im just falling into this huge pit of confusion..
hopefully help is on the way
ok heres my code
Code:
/* NODE.H */
class Node {
public:
Node();
~Node();
Node* makeNode(const char *s, int a, int b);
private:
string msg;
int s;
int t;
Node* nextPtr;
};
Code:
/* NODE.CPP */
#include "node.h"
Node * Node::makeNode(const char *s, int a, int b) {
Node * newNodePtr = (Node *)malloc(sizeof(Node));
if(newNodePtr == NULL) {
cerr << "Out of memory" << endl;
}
else {
newNodePtr->msg = s;
newNodePtr->t = a;
newNodePtr->s = b;
newNodePtr->nextPtr = NULL;
}
return newNodePtr;
}
Code:
/* LINKEDLIST.H */
#include "Node.h"
class LinkedList {
public:
LinkedList(LinkedList* listPtr); // constructor
void Insert(LinkedList* listPtr);
void insertItem(LinkedList* listPtr, const char * s, int type, int status);
int deleteNodes(LinkedList* listPtr);
private:
int count;
Node* headPtr;
};
hopefully you can see from this, im TRYING to implement it so that i have a linked list of nodes.. not sure if that private member Node* headPtr should be LinkedList * headPtr or not...
i want to be able to do things like..
Code:
Node * newNode;
newNode->headPtr->msg = "hello";
so im not sure if those declarations and the structure are correct..
and finally the linkedlist.cpp where makeNode error (and many others) was occuring..
Code:
/* LINKEDLIST.CPP */
#include "LinkedList.h"
#include "Node.h"
void LinkedList::insertItem(LinkedList* listPtr, const char * item, int type, int status) {
Node* newNodePtr = makeNode(item, type, status);
Node* prevPtr = NULL;
if (position == 0)
{
newNodePtr->nextPtr = listPtr->headPtr;
listPtr->headPtr = newNodePtr;
}
else
{
prevPtr = setPosition(listPtr, position-1);
newNodePtr->nextPtr = prevPtr->nextPtr;
prevPtr->nextPtr = newNodePtr;
}
listPtr->count++;
}
i know thats heaps of code to take in.. hoep you can help
THANKS