My lecturer has supplied some pseudocode in his course notes for the n-Queens problem. Unfortunately I’m having a bit of a hard time understanding it to do an implementation in Java. The pseudocode in question is:
Queens (currentBoard , currentRow, n) :
if currentRow == n:
if currentBoard is legal:
return <currentBoard, 1>
else:
return <currentBoard, 0>
else:
for k = 1..n:
newBoard = currentBoard + <currentRow+1, k>
board [k], success[k] = Queens(newBoard, currentRow+1, n)
kmax = index of max(success[k])
return <board[kmax], success[kmax]>
Most of it I understand but I’m not sure what I’m meant to do with the parts of the pseudocode that are in the angle brackets.
The angle brackets here just say, that multiple “objects” are returned.
So, for example, this code
returns on the one hand the
currentBoardobject and on the other hand a simple1.In this code
you can see that both objects are stored into different variables, to board goes into
board[k]and the number goes intosuccess[k].