linked list in vc++
Hi everyone. I''ve been programming for a while in DJGPP, but lately I decided to try to make the leap to windows so that I could try OpenGL. However, a couple of things have been giving me trouble. First is linked lists. Here''s a link to a sample of my linked list code that''s always worked fine in DJGPP, but which gives me runtime errors in VC++. I''d greatly appreciate it if someone could tell me what''s wrong with it, or could direct me to some source for a linked list that will work in VC.
Thanks in advance,
Eben Olson
The problem you are having is a result of having a NULL pointer in your checklist() function after calling delobj() on one of your nodes... To solve the problem temporarly save the memory address of the next node before deleting the current node.
Therefore change your checklist function to look like this...
void LIST::checklist()
{
NODE *temp;
NODE *nextNode;
for (temp = base; temp != NULL; )
{
if (temp->value<0)
{
nextNode = temp->next;
delobj(temp);
temp = nextNode;
}
else
temp = temp->next;
}
}
hope this helps
Edited by - POW on June 4, 2000 6:55:44 PM
Therefore change your checklist function to look like this...
void LIST::checklist()
{
NODE *temp;
NODE *nextNode;
for (temp = base; temp != NULL; )
{
if (temp->value<0)
{
nextNode = temp->next;
delobj(temp);
temp = nextNode;
}
else
temp = temp->next;
}
}
hope this helps
Edited by - POW on June 4, 2000 6:55:44 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement