tommycahir,
Ok, since I have already provided a way to do it using Quantum::Superpositions, I should point out that there certainly are simpler solutions. Since your goal is just to visit all routers, order really should not matter:
my @visited = (1 .. 5);
my %unvisited = map { $_ => undef } 1 .. 9;
while ( %unvisited ) {
delete @{unvisited}{@visited};
for ( keys %unvisited ) {
visit( $_, \%unvisited ); # Adds routers to %unvisited
push @visited , $_;
}
}
Now if for some reason order is important to you, you can reverse the array/hash for the stack.
my %visited = map { $_ => undef } (1 .. 4);
my @unvisited = (1 .. 9);
while ( @unvisited ) {
my $router = shift @unvisited;
next if exists $visited{$router};
visit ( $router, \@unvisited ); # Adds routers to @unvisited
$visited{$router} = undef;
}
I hope these solutions are helpful.
Cheers - L~R
|