in reply to How to implement Linked List
Perl has built in fully dynamic data structures - arrays and hashes. These are in most cases sufficient for resident data needs. Can you explain why you need a linked list - is this a practical application or an academic exercise?
Here's something cobbled together - a class that will give you linked list:
package Data::LinkedList; sub new { my $pkg = shift; my %proto = @_; bless \%proto, $pkg; } sub data { my $self = shift; @_ ? ($self->{data} = shift) : $self->{data}; } sub next { my $self = shift; @_ ? ($self->{next} = shift) : $self->{next}; } 1; __END__ my $ele1 = Data::LinkedList->new( data => 'abel' ); my $ele2 = Data::LinkedList->new( data => 'baker', next => $ele1);
--
Oh Lord, won’t you burn me a Knoppix CD ?
My friends all rate Windows, I must disagree.
Your powers of persuasion will set them all free,
So oh Lord, won’t you burn me a Knoppix CD ?
(Missquoting Janis Joplin)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How to implement Linked List
by tilly (Archbishop) on Dec 19, 2006 at 01:10 UTC | |
Re^2: How to implement Linked List
by msk_0984 (Friar) on Dec 18, 2006 at 12:58 UTC | |
by Melly (Chaplain) on Dec 18, 2006 at 13:29 UTC |
In Section
Seekers of Perl Wisdom