in reply to Re^2: Perl linked list
in thread Perl linked list
(It could be much simpler, but I wanted to stay at a relative beginner level.use strict; use warnings; my $pt = { value => "D", next => undef }; my $pt2 = {value => "C", next => $pt}; $pt = {value => "B", next => $pt2}; my $L = { value => "A", next => $pt};
It took me less than 5 minutes to write the code to count the nodes, but I'll reveal it only later, once I am sure that this cannot used for other purpose.
My iterative solution subroutine prints out the node being visited and the node count as follows:
Very easy.ABCD 4
A recursive solution would probably be even simpler, but I haven't tried so far.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Perl linked list
by Perl_is_Perl (Initiate) on Mar 31, 2015 at 19:15 UTC | |
by Laurent_R (Canon) on Mar 31, 2015 at 20:14 UTC | |
|
Re^4: Perl linked list
by Perl_is_Perl (Initiate) on Mar 31, 2015 at 21:09 UTC | |
by Laurent_R (Canon) on Apr 01, 2015 at 07:23 UTC |