How do I insert a number in a linked list?

Started by
3 comments, last by cybo 21 years, 5 months ago
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
Paranoid Lunatic with a heart of gold
Advertisement
are you using the standard library list or your hand-rolled version... or something else? (c:
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;
}
Paranoid Lunatic with a heart of gold
I think you should post more code

C++: Boost | GOTW tips | GOTW articles | FAQ lite | CUJ

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.

This topic is closed to new replies.

Advertisement