28
The last possiblity is that a conflict exists, but the new queen has run
out of room. In this case we backtrack:
Pseudocode for N-Queens
Pseudocode for N-Queens
❸
❸repeat these steps
repeat these steps
❐
❐if there are no conflicts with the queens…
if there are no conflicts with the queens…
❐
❐else if there is a conflict and there is room to
else if there is a conflict and there is room to
shift the current queen rightward…
shift the current queen rightward…
❐
❐else if there is a conflict and there is no room
else if there is a conflict and there is no room
to shift the current queen rightward…
to shift the current queen rightward…
Backtrack!
Keep popping the stack, and reducing filled
by 1, until you reach a row where the queen
can be shifted rightward. Shift this queen right.