Go中的removeElement函数是否有类似Java的Vector类在其Vector类中?
题
我正在将一些Java代码移植到Google的Go语言中,并且我转换了所有代码,除了在一个非常流畅的端口之后我被困在一个部分上。我的Go代码看起来像这样,我正在讨论的部分被注释掉了:
func main() {
var puzzleHistory * vector.Vector;
puzzleHistory = vector.New(0);
var puzzle PegPuzzle;
puzzle.InitPegPuzzle(3,2);
puzzleHistory.Push(puzzle);
var copyPuzzle PegPuzzle;
var currentPuzzle PegPuzzle;
currentPuzzle = puzzleHistory.At(0).(PegPuzzle);
isDone := false;
for !isDone {
currentPuzzle = puzzleHistory.At(0).(PegPuzzle);
currentPuzzle.findAllValidMoves();
for i := 0; i < currentPuzzle.validMoves.Len(); i++ {
copyPuzzle.NewPegPuzzle(currentPuzzle.holes, currentPuzzle.movesAlreadyDone);
copyPuzzle.doMove(currentPuzzle.validMoves.At(i).(Move));
// There is no function in Go's Vector that will remove an element like Java's Vector
//puzzleHistory.removeElement(currentPuzzle);
copyPuzzle.findAllValidMoves();
if copyPuzzle.validMoves.Len() != 0 {
puzzleHistory.Push(copyPuzzle);
}
if copyPuzzle.isSolutionPuzzle() {
fmt.Printf("Puzzle Solved");
copyPuzzle.show();
isDone = true;
}
}
}
}
如果没有可用的版本,我相信没有...有没有人知道如何自己实现这样的事情?
解决方案
Vector.Delete(i)怎么样?
其他提示
现在Go不支持通用等式运算符。所以你必须写一些迭代向量的东西并删除正确的东西。
不隶属于 StackOverflow