I've created all sorts of ADTs in C/C++. I've used even more (Standard Template Library was great!). I've never even thought about it in perl. I'm sure someone will come along and tell me why it was such a great thing for what they were doing. That's fine - but AoH, HoA, HoHoHoH, AoAoH, etc., these kinda take the place of those other container types that you need so badly in other languages.
That's not to say it can't be done in Perl, or even that, as an excersise in learning how references work, it's not worth doing in perl. Just that I've never had a reason to use it.
Perl has great data structures internally which seem to solve the problems: hashes and arrays. And I can choose whichever one makes sense. Iterating over them is easy, whether that's foreach over an array, over the keys to a hash, or while/each over a hash.
Usually, I think, a linked list is used to make things easy to add/remove from the beginning and the end of the list. That's what shift, unshift, push, and pop are for. Perl is already likely using a linked list as it is. And it's probably got some other abstractions put into its "array" type, too, to give you direct access to an arbitrary scalar (ref's are scalars, too ;->) in the array, to always know the length, etc.
Circular lists - such that instead of falling off the list at the end, you simply wrap around to the beginning - are not something I found a lot of use for in C/C++ anyway, so perhaps you may still find the same use for them in perl. Mind you, if all you want to do is be able to start at an arbitrary point in the list, you can do the same in perl pretty easily: foreach my $s (@list[$n..$#list,0..$n-1]) { ... }.
I guess my point is ... you might be better off learning perl idioms to get your job done faster rather than trying to write C/C++ in perl. ;-)
In reply to Re: OOP/Linked List Question
by Tanktalus
in thread OOP/Linked List Question
by hok_si_la
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |