Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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.

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]
[LanX]: Not Quite Canada
[Discipulus]: have you been fired?!?
[LanX]: remote rules, I've been offered jobs in the US with the promise to stay outside
[MidLifeXis]: Nope. Just looking around, as there are multiple culture and business changes in the area I am in.
[MidLifeXis]: not yet, anyway. Who knows. Just do my best and whatever happens happens.
[LanX]: should be even easier for you
[Discipulus]: oh well we cant afford two monks fired in a day!
[LanX]: any news from tye ' s search?
[MidLifeXis]: Ugh - who else?
[Discipulus]: so the right term is 'gired'

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (16)
As of 2017-03-23 12:43 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (286 votes). Check out past polls.