in reply to Linked List
Hi code-ninja!
When you pass through the list you check if the current element is the one you want to remove:
and if it isn't, you move to the next element:if($temp->[VAL] == $ele) {
However the pred-Element still stays the first one ... so when you remove the 16, you would link the 25 directly after the 1. You will need to adjust pred also.$temp = $temp->[NEXT];
note: your code also needs some adjustment if you want the possibility to delete the first element.
HTH, Rata
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Linked List
by code-ninja (Scribe) on Sep 04, 2013 at 06:57 UTC |
In Section
Seekers of Perl Wisdom