in reply to How to implement Linked List
This is the same as the hash version above, but using arrays. You would travers this list like this:$c = ['c', undef]; $b = ['b', undef]; $a = ['a', undef]; $a->[1] = $b; $b->[1] = $c;
This is no different than the hash version above, but should be a bit more efficient.my $current = $a; while (defined $current) { my $value = $current->[0]; ... $current = $current->{1]; }
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to implement Linked List
by msk_0984 (Friar) on Dec 19, 2006 at 05:50 UTC |