simple linked list operations

-- removed since resolved
Last edited on
1
2
3
4
while(cp!=NULL){
pp=cp;
cp=cp->next;
}

Your loop ends when cp == NULL. Then, you immediately try to de-reference and use it here:

 
cp->item=newItem;

That's why it's throwing an access violation error - you're trying to de-reference a null pointer.
Last edited on
-- removed since resolved
Last edited on
changed code added further down
Last edited on
well something is definitely wrong with my switches, as I have to type in 55 to get case 7 running........ -.-
http://cplusplus.com/doc/tutorial/control/

Go look up on how to use switch cases. (Located at the very bottom of the page)

On line 53, you are declaring the function exit instead of calling it. Lose the void.
exit is located in <cstdio>.

thanks man, this looks better I hope, doesnt throw a violation :>

That will replace the last item in the list rather than adding a new element.

Use cp to find the very end of the list, then allocate a new element at the end of the chain. It's comparable to what you did in your push_front function, but backward.
Last edited on
@navlelo
The reason you have to type '55' to get case 7 running, is because the ASCII value of 7, IS 55. Try removing the single quotes around the numbers, to use the inputted number instead of its value.
-- removed since resolved
Last edited on
Go back to a switch(). You were right to use it, just wrong in HOW you used it. Look up "break" in regards to switch. Without it, every case will run starting from the one you input.
thanks for all the help so far guys, got all but 1 method working now, will work on that later :) then all I gotta do is sort my menu/switch problem and it's all gooood <3 love you all :D
Topic archived. No new replies allowed.