NQueens Problem - Online Code

Description

Generate all possible solutions to the N queens problem.The board is represented by board[1:N], which records for each column whether there is a queen in that column, and if so, which row it occupies. In particular, board[j] = i if there is a queen in row i of column j = 0 otherwise

Source Code

class nQueens {

   static int N = 8;

   static int numSolutions = 0;



   static boolean safe(int row, int column, int[] board) {



      for (int j=1; j<column; j++) {

         if (board[column-j] == row   ||

... (login or register to view full code)

To view full code, you must Login or Register, its FREE.

Hey, registering yourself just takes less than a minute and opens up a whole new GetGyan experience.




Comments

No comment yet. Be the first to post a comment.