mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-11-14 23:12:58 +08:00
Add Hamiltonian cycle.
This commit is contained in:
parent
569c6ae452
commit
d2c6d14acd
@ -91,6 +91,7 @@ function hamiltonianCycleRecursive({
|
|||||||
cycle: currentCycle,
|
cycle: currentCycle,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// BACKTRACKING.
|
||||||
// Remove candidate vertex from cycle path in order to try another one.
|
// Remove candidate vertex from cycle path in order to try another one.
|
||||||
currentCycle.pop();
|
currentCycle.pop();
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,7 @@ function nQueensRecursive(solutions, previousQueensPositions, queensCount, rowIn
|
|||||||
// Try to place all other queens as well.
|
// Try to place all other queens as well.
|
||||||
nQueensRecursive(solutions, queensPositions, queensCount, rowIndex + 1);
|
nQueensRecursive(solutions, queensPositions, queensCount, rowIndex + 1);
|
||||||
|
|
||||||
|
// BACKTRACKING.
|
||||||
// Remove the queen from the row to avoid isSafe() returning false.
|
// Remove the queen from the row to avoid isSafe() returning false.
|
||||||
queensPositions[rowIndex] = null;
|
queensPositions[rowIndex] = null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user