develooper Front page | perl.beginners | Postings from December 2002

linked list's

Thread Next
From:
Mark Goland
Date:
December 8, 2002 01:19
Subject:
linked list's
Message ID:
000c01c29e9a$d7548d30$d5ebbf18@tanya
hi all,

I am having problems printing this doubly list. the bug statment prints the
expacted so I think I have the list setup right, but I cant get this list to
print in reverse... any ideas ??

Thanx in Advance

#!/usr/bin/perl -w

$debug=1;

for($i=1;$i<10;$i++){
      $list = {value=>$i,prev=>$list,next=>${prev} };
 print "prev=$prev\tlist=$list\n" if( $debug);
      $prev= $list;

}

$iterator = $list;
while($iterator){
      print "$iterator->{value} ";
      $iterator = $iterator->{next};
#$iterator=$iterator->{prev};
}
print "\n";


print "In reverse \n";
$iterator = $prev;
while($iterator){
 print "$iterator->{value} ";
 $iterator= $iterator->{prev};
}


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About