JavaのVectorクラスにあるようなベクターパッケージ用のGoのremoveElement関数のバージョンはありますか?
質問
いくつかの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