




![static void placeQueen (int[] [] B, int i, int j) and static void removeQuee (int[l[i B, int i, int j) The first function inc](http://img.homeworklib.com/images/57a9623d-ad6a-4714-a599-280a6c2187c8.png?x-oss-process=image/resize,w_560)
can i get some help with this program
public class NQueenProblem{
final int N =8;
void printSolution(int boade[])
{
for (int i=0;i<N;i++){
for(int j=0;j<N;j++){
System.out.print(" "+board[i])[j] + " ");
}
boolean isSafe(int board[][],int row,int col)
{
int i,j;
for(i=0;i<col;i++)
{
if(board[i][j]==1)
return false;
for(i=row; j=col;j>= 0 && i< N;i++,j--)
if(board[i][j]==1)
return false;
return true;
}
boolean solveNQUtil(int board[][], int col){
if(col>=N)
return true;
for(int i=0;i<N;i++)
if( isSafe(board,i,col)
board[i][col]=1;
if( solveNQUtil(board,col+1)==true)
return true;
board[i][col]=0;
}
return false'
}
boolean solveNQ()
{
int board[][]= { { 0,0,0,0,0,0,0,0},
{ 0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0} };
if(solveNQUtil(board,0)== false) {
System.out.print("Solution does not exist");
return false;}
printSolution(board);
return true;
}
public static void main(String args[])
{
NQueenProblem Queen = new NQuuenProblem();
Queen.solveNQ();
}
}
CMPS 12B Introduction to Data Structures Programming Assignment 2 In this project, you will write...
in c++
Purpose: This lab will give you experience
harnessing an existing backtracking algorithm for the eight queens
problem, and seeing its results displayed on your console window
(that is, the location of standard output).
Lab
A mostly complete version of the eight queens problem has been
provided for you to download. This version has the class Queens
nearly completed.
You are to provide missing logic for the class Queens that will
enable it to create a two-dimensional array that...
Assignment 2 In this assignment, you will write two short programs to solve problems using recursion. 1. Initial Setup Log in to Unix. Run the setup script for Assignment 2 by typing: setup 2 2. Towers of Hanoi Legend has it that in a temple in the Far East, priests are attempting to move a stack of disks from one peg to another. The initial stack had 64 disks threaded onto one peg and arranged from bottom to top by...
Please help i need a C++ version of this code and keep getting
java versions. Please C++ only
Purpose: This lab will give you experience
harnessing an existing backtracking algorithm for the eight queens
problem, and seeing its results displayed on your console window
(that is, the location of standard output).
Lab
A mostly complete version of the eight queens problem has been
provided for you to download. This version has the class Queens
nearly completed.
You are to provide...
Complete the program that solves the Eight Queens problem. The program’s output should look similar to: |1|0|0|0|0|0|0|0| |0|0|0|0|0|0|1|0| |0|0|0|0|1|0|0|0| |0|0|0|0|0|0|0|1| |0|1|0|0|0|0|0|0| |0|0|0|1|0|0|0|0| |0|0|0|0|0|1|0|0| |0|0|1|0|0|0|0|0| Use the Queens class given. In your implementation of the Queens class, complete the body of all methods marked as “To be implemented in Programming Problem 1.” Do not change any of the global variable declarations, constructor or placeQueens methods. Here is what I have so far with notes of what is needed. public class Queens...
please explain/ comment
3. Eight Queens Write a program that places eight queens on a chessboard (8 x 8 board) such that no queen is "attacking" another. Queens in chess can move vertically, horizontally, or diagonally. How you solve this problem is entirely up to you. You may choose to write a recursive program or an iterative (i.e., non-recursive) program. You will not be penalized/rewarded for choosing one method or another. Do what is easiest for you. 3.1. Output Below...
Main objective: Solve the n queens problems. You have to place n queens on an n × n chessboard such that no two attack each other. Important: the chessboard should be indexed starting from 1, in standard (x, y) coordinates. Thus, (4, 3) refers to the square in the 4th column and 3rd row. We have a slight twist in this assignment. We will take as input the position of one queen, and have to generate a solution with a...
================Data Structures C++=============== – Implement the Eight Queens Problem This is an object oriented program. This is #1 on page 187 of your book with ONE difference, I’m requiring you add a client program to test your code (a main). If you have the old book the question says “Complete the Queen and Board class for the Eight Queens problem.” On page 179 of your book is a function placeQueens that solves the Eight Queens problem. On page 180 of...
Complete the program that solves the Eight Queens problem in java only please (pages 318 through 320). The program’s output should look similar to: |1|0|0|0|0|0|0|0| |0|0|0|0|0|0|1|0| |0|0|0|0|1|0|0|0| |0|0|0|0|0|0|0|1| |0|1|0|0|0|0|0|0| |0|0|0|1|0|0|0|0| |0|0|0|0|0|1|0|0| |0|0|1|0|0|0|0|0| PlaceQueens(in currColumn:integer) //places queens in columns numbered currColumn through 8 If (currColumn>8){ The problem is solved } Else { While(unconsidered squares exist in curr column and the problem is unsolved ){ Determine the next square in column currColumn that is not under attack by a queen in an...
Write a program to place eight queens on an 8 x 8 chessboard in such a way that one queen is to be in each row. A program will use 2 DIMENIONAL array x[r][c] to do this configuration. If x[r] has value c, then in row r there is a queen in column c. Write a program that asks a user to enter the columns that contain queens in the 8 rows. The program then places the queens in these...
Can someone please complete the "allTheQueensAreSafe" function? #include <stdio.h> #include <stdlib.h> void printBoard(int *whichRow, int n) { int row, col; for (row = 0; row < n; row++) { for (col = 0; col < n; col++) { printf("%c", (whichRow[col] == row) ? 'Q' : '.'); } printf("\n"); } printf("\n"); } int allTheQueensAreSafe(int *whichRow, int n, int currentCol) { // TODO: Write a function that returns 1 if all the queens represented by // this array are safe (i.e., none...