Thread Rekursion mittels Array
(7 answers)
Opened by peterb at 2017-12-05 11:03
So?
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 #!/usr/bin/perl use strict; use warnings; my $start = '2A'; my %data; for my $line (<DATA>) { chomp $line; my ($key, $value) = split / --> /, $line; if ( exists $data{$key} ) { push @{ $data{$key} }, $value; } else { $data{$key} = [$value]; } } do_tree( $start ); sub do_tree { my $start = shift; for my $node (@{ $data{ $start } }) { print "$start --> $node\n"; do_tree( $node ); } } __DATA__ 1A --> 2A 1A --> 2B 2A --> 4A 2A --> 5A 4A --> 5A 2B --> 3A 3A --> 4A Lieben Gruss Pörl.
|