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