Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Linked List

by Ratazong (Monsignor)
on Sep 04, 2013 at 06:51 UTC ( #1052224=note: print w/replies, xml ) Need Help??

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:

if($temp->[VAL] == $ele) {
and if it isn't, you move to the next element:
$temp = $temp->[NEXT];
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.

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
    perfect. That was a stupid mistake. :/
    ... } else { $temp = $temp->[NEXT]; $pred = $pred->[NEXT]; # this is what you are saying. } ...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1052224]
[erix]: choroba I believe you ;)
[1nickt]: Corion I assume you are talking about Retry? Attempt doesn;t offer callbacks and has a much simpler interface. (Also written by someone I trust...)
[perldigious]: I train for long portaging/rowing trips by carrying my kayak to the river about a half mile from my house 2-3 times a week depending on weather... but due to a lingering winter, I haven't had long to train this year.

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2017-05-24 12:58 GMT
Find Nodes?
    Voting Booth?