Hi Jim,

"JC(oesd)" wrote:

> I just had a friend explain in some little detail about linked lists in C
> using structures.
>
> How would such a thing be done with Perl?

In brief, Perl already has a built-in linked list structure.  It is called Array.

> This may help me understand C's
> version a little better.

Probably not.  Perl and C take very different paths when handling low-level 
functionality.  In Perl, you don't have the precisely typed variables that you use 
with C.  Nor do you have the straightforward definition of new types that you get with 
a C struct or C++ class.  Although you could artificially construct a linked list in 
Perl, it probably would not make sense, or render any results you could not obtain 
using the built-in containers.

I strongly suspect that the Perl Array type is actually implemented on a linked list.  
It operates in very similar ways, with push and pop providing stack-type 
functionality, and shift accessing the first-in item of a queue.  Also, the Perl Array 
type allows the deletion of elements [but DON'T DO IT while iterating through the 
array], which is a very linked-list sort of offering:  In a list you can simply 
re-link the node preceding the deltion node to the node following it, then delete the 
deletion node itself.  In a true array you would have to shift the values in all 
subsequent nodes backwards to fill in the gap.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to