Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: How to implement Linked List

by gam3 (Curate)
on Dec 19, 2006 at 04:07 UTC ( #590600=note: print w/ replies, xml ) Need Help??

in reply to How to implement Linked List

A simple linked list would be [ 'a' [ 'b' [ 'c', undef]]]. This is more clear if you look at it like this:

$c = ['c', undef]; $b = ['b', undef]; $a = ['a', undef]; $a->[1] = $b; $b->[1] = $c;
This is the same as the hash version above, but using arrays. You would travers this list like this:
my $current = $a; while (defined $current) { my $value = $current->[0]; ... $current = $current->{1]; }
This is no different than the hash version above, but should be a bit more efficient.

The main point is that a linked list is made up of elements that contain data and a pointer to the next element. In the case of a double linked list 2 pointers -- one to the previous element and one to the next element.

-- gam3
A picture is worth a thousand words, but takes 200K.

Comment on Re: How to implement Linked List
Select or Download Code
Replies are listed 'Best First'.
Re^2: How to implement Linked List
by msk_0984 (Friar) on Dec 19, 2006 at 05:50 UTC
    Hi Monks,

            Firstly i would like to thank you for ur replies and it was really a good thing to get the ideas and views of well experienced people.

            Most said Perl has built in fully dynamic data structures - arrays and hashes. These are in most cases sufficient for resident data needs. We have the extended featured functions for th ease in order to exploit the programming abilities....

    FUNCTIONS: pop , push , splice , shift , unshift and many more and dont want to use etc.....

    As jonadab said ...........

    It's kinda like asking, "How do I implement an insertion sort in Perl?" or, to use a non-Perl example, "How do I tack in a speedboat?" Everyone's going to look at you funny and ask, "Why?"

    But any wayz i felt it some thing like of learning a lot from all of you.

    Work Hard Party Harderrr!!
    Sushil Kumar

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://590600]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2015-11-29 09:00 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (750 votes), past polls