Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

cybo

How do I insert a number in a linked list?

This topic is 5769 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have it so I can insert before the head of the list, and when the list is empty. But my problem is inserting in the middle or at the end. (Im using C++ by the way) I have to insert the number in sorted order so I need to check what each nodes value is....But I dont know where to go from there....any help is appreicated! thanks

Share this post


Link to post
Share on other sites
Advertisement
hand version we have to make our own class....here is the code where Im getting trouble


Im getting an acess violation

Node * getLink(); //.h

Node * Node::getLink() //.cpp
{
return link;
}

Share this post


Link to post
Share on other sites
Here''s the basic technique: Take the node BEFORE the insertion point, and make it point to the new node. Then make the new node point to the node AFTER the insertion point.


Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!