-
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
http://sourcepost.sytes.net/source/s...source_id=1670
To Email me back, email me at [email protected]
-
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:
node name
pointer
and use an extended arrow to represent which node is being pointed to.
Code:
Say I start with this:
previous
next------------>current
next------------>currentNext
next
with goal being to delete current node of a singly linked list and end up with this:
previous
next------------->currentNext
next
//steps
previous->next = current->next;
delete current;
It's easier for me to get the reassignments correctly if I see what I am doing. For what it's worth.
-
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 .