-
After your done adding the node set the pointer to NULL. Do a test at the beginning on the added node for NULL and return if True(or better yet throw an exception since you shouldn't be passing it NULL pointers to add). And you have no need to be embarassed ;)
-
If you can accurately describe what you want to do, it can usually be done. Here are two options for what I think you might want to be do:
Code:
void Link::AddNode(Node *W){
if(W != NULL)
{
Node * newNode = new Node;
newNode->name = W->name;
newNode = NULL;
if(start == NULL)
start = newNode;
else
{
//if W has the same address or the same name as start don't add it to the list
if(W != start && W->name != start->name)
{
newNode->next = start;
start = newNode;
}
}
}
}
//Version two
void Link::AddNode(Node *W){
if(W != NULL)
{
//search list for W->name
Node * current = start;
while(current != NULL && current->name != start->name)
current = current->name;
if(current == NULL) //name not in list
{
//add name in W to front of list
Node * newNode = new Node;
newNode->name = W->name;
newNode = NULL;
if(start == NULL)
start = newNode;
else
{
newNode->next = start;
start = newNode;
}
}
}
}