punitpawar has asked for the wisdom of the Perl Monks concerning the following question:
$head ={ data=>2 next=>undef; ## or the next node to which it is linked to }
my @elements; my $curr=$head; ## I am trying to make my curr pointer start from t +he head while (1){ last unless ($curr->{next} == $head); # here I am trying to +check that the next element is not head. And if is then break out of +the loop print "data : $curr->{data} \n"; push(@elements,$curr->{data}); $curr = $curr->{next}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to find all the elements in a circular linked list
by Athanasius (Archbishop) on Feb 10, 2016 at 03:32 UTC | |
|
Re: How to find all the elements in a circular linked list
by GrandFather (Saint) on Feb 10, 2016 at 01:05 UTC |