Java가 벡터 클래스에 보유한 벡터 패키지에 대한 Go에 RemoveElement 함수 버전이 있습니까?

StackOverflow https://stackoverflow.com/questions/1802102

  •  05-07-2019
  •  | 
  •  

문제

나는 일부 Java 코드를 Google의 Go Language로 포팅하고 있으며 놀랍도록 부드러운 포트 후 한 부분에 붙어있는 것을 제외하고는 모든 코드를 변환합니다. My 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는 일반 평등 연산자를 지원하지 않습니다. 따라서 벡터 위에 반복하고 올바른 것을 제거하는 것을 써야합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top