هل هناك نسخة من وظيفة removeElement في العودة لحزمة ناقلات مثل ديها جافا في الدرجة المتجهات لها؟

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

  •  05-07-2019
  •  | 
  •  

سؤال

وأنا ترقية على بعض شفرة جافا في اللغة العودة غوغل وأنا تحويل كافة التعليمات البرمجية إلا أنا عالقة على جزء واحد فقط بعد ميناء سلس مثير للدهشة. بلدي الذهاب كود يشبه هذا وعلق القسم انا اتحدث عن الخروج:

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 (ط)؟

نصائح أخرى

والآن العودة لا يدعم المشغلين المساواة العامة. لذلك عليك أن أكتب شيئا أن تتكرر على النواقل ويزيل واحدة صحيحة.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top