Archived

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

cybo

How do I insert a number in a linked list?

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
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