看板 Perl 關於我們 聯絡資訊
小的在寫一個 印出所有字串中字元排列組合 的程式 在遞迴呼叫的時候出了一點問題 不知道有無大大可以幫我看一下, 再印出 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
typeotoco:喔喔 找到問題了 list沒加@, 陣列subscript 沒加$ 12/07 22:16
typeotoco:太腦殘了, 謝謝下面的大大提供範例 感謝 12/07 22:16