NonAttackingQueens

NonAttackingQueens - /* / NonAttackingQueens.java Author:...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // NonAttackingQueens.java Author: Lewis/Loftus // // Solution to Programming Project 11.6 // // A recursive program that solves the Non-attacking Queens problem. //******************************************************************** public class NonAttackingQueens { int[] queens; // Queen i is always placed in row i. The // column is variable. // queens[i] represents the column of the ith row // where the ith queen is final int NUM_QUEENS = 8; public NonAttackingQueens() { queens = new int[NUM_QUEENS]; } //----------------------------------------------------------------- // Returns true if a queen queenNumber can be placed in column //----------------------------------------------------------------- boolean canPlace(int queenNumber, int column) { for (int row = 0; row < queenNumber; row++) // check all rows above queenNumber row { if (queens[row] == column) // in the same column return false; if (Math.abs(queens[row] - column) == Math.abs(row - queenNumber)) //
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/17/2011 for the course COP 3530 taught by Professor Davis during the Spring '08 term at University of Florida.

Page1 / 2

NonAttackingQueens - /* / NonAttackingQueens.java Author:...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online