Shaveta_Chawla has asked for the wisdom of the Perl Monks concerning the following question:
A linked list can be created in perl like this::
but if i want to insert a new node say 11 after a specific position say after 6, how can i do that??? Or is there any better way to create a Linked List in perl??my ($head, $tail); $tail = append($head, 1); for $value ( 2 .. 10 ) { $tail = append($tail, $value); } sub append { my($list, $value) = @_; my $node = { VALUE => $value }; if ($list) { $node->{LINK} = $list->{LINK}; $list->{LINK} = $node; } else { $_[0] = $node; } return $node; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Linked list in Perl
by Arunbear (Prior) on Sep 28, 2012 at 12:25 UTC | |
by Anonymous Monk on Sep 28, 2012 at 12:46 UTC | |
Re: Linked list in Perl
by grizzley (Chaplain) on Sep 28, 2012 at 12:21 UTC | |
Re: Linked list in Perl
by Anonymous Monk on Sep 28, 2012 at 12:05 UTC | |
Re: Linked list in Perl
by Anonymous Monk on Sep 28, 2012 at 12:19 UTC | |
Re: Linked list in Perl
by GrandFather (Saint) on Sep 30, 2012 at 21:45 UTC | |
Re: Linked list in Perl
by sundialsvc4 (Abbot) on Sep 28, 2012 at 17:12 UTC | |
by Anonymous Monk on Sep 29, 2012 at 09:36 UTC | |
Re: Linked list in Perl
by LanX (Saint) on Sep 29, 2012 at 23:26 UTC |
Back to
Seekers of Perl Wisdom