Removal on Linked List
im doing my delete function right now, and im only able to delete the first node in the Linked List, and when i try to delete lets say the second node, i get this Exception Handling Error and the Program terminates, and i have no idea why its doing that.
heres a link to my program again, the remove function starts on line 110, and the while loop is on line 130 i think. thanx a lot
To Email me back, email me at DRFUNKENSTINE@aol.com
You have to delete the last node first and then work your way back towards the head.
arent i already doing that, because on my remove function i make cur = prev->next, then i say prev->next = cur->next, and then i delete cur. isnt that right?
when working out what to do with linked lists here's a technique I use to help: draw a diagram of what I am trying to do before I write the code. For a singly linked list I use two lines to represent a node like this:
and use an extended arrow to represent which node is being pointed to.
It's easier for me to get the reassignments correctly if I see what I am doing. For what it's worth.
Say I start with this:
with goal being to delete current node of a singly linked list and end up with this:
previous->next = current->next;
O, sorry, you might be. I didn't look at your code. That just sounded like the answer to ur problem from how you described it. I know, I'm LAZY:D .