草庐IT

iterPermutation

全部标签

go - 使用闭包在 Go 中编写下一个排列,我的代码有什么问题

我编写了一个使用闭包的函数“iterPermutation”。我想从我做不到的闭包中返回数组和bool值。所以只尝试了数组,但它仍然报错cannotusefuncliteral(typefunc()[]int)astype[]intinreturnargument我想像这样使用iterPermutationa:=[]int{0,1,2,3,4}nextPermutation,exists:=iterPermutation(a)forexists{nextPermutation()}funciterPermutation(a[]int)[]int{returnfunc()[]int{i: