linked list in vc++

Started by
2 comments, last by Baniel 23 years, 11 months ago
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
Advertisement
Your node class needs a constructor i believe and a destructor
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
Thank you so much! Now it doesn''t crash anymore!

This topic is closed to new replies.

Advertisement