作者typeotoco (打字男)
看板Perl
标题[问题] 递回呼叫
时间Sun Dec 7 12:02:35 2008
小的在写一个 印出所有字串中字元排列组合 的程式
在递回呼叫的时候出了一点问题
不知道有无大大可以帮我看一下,
再印出 mylist 的地方只有第一次印的出来, 不知道为什麽?
是我参数传递有错吗? 谢谢
main 呼叫:
&perm(0,$size-1,\@array);
sub perm{
my ($head, $tail, $list) = @_ ;
my $indexj;
print "head-tail: $head, $tail\n";
print "mylist @$list\n" ;
if( $head == $tail ){ #stop condition
print "result: @$list\n" ;
}
else{
for($indexj = $head ; $indexj <= $tail ; $indexj++ ){
($list[head], $list[indexj]) = ($list[indexj], $list[head]) ;
&perm($head+1,$tail,\@list);
($list[head], $list[indexj]) = ($list[indexj], $list[head]) ;
}
}
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.169.88.182
1F:→ typeotoco:喔喔 找到问题了 list没加@, 阵列subscript 没加$ 12/07 22:16
2F:→ typeotoco:太脑残了, 谢谢下面的大大提供范例 感谢 12/07 22:16