From the course: Code Clinic: C++

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Find all solutions

Find all solutions - C++ Tutorial

From the course: Code Clinic: C++

Start my 1-month free trial

Find all solutions

- [Instructor] For my solution to the queens challenge, I chose to represent the board as an array of integers. The index of each array element represents a row on the board, and the value of that element indicates which column along that row contains a queen. For example, the first element in the array shown here represents a queen at row zero, column one. Remember that arrays are zero indexed in C++. The second element is a queen on row one, column three. The third is a queen on row two, column five, and so on. Conveniently, by representing the location of queens as an array like this, I guarantee that every queen will have her own row, and as long as all of the values in the array are different, I know that each queen has her own column too. I implemented my solution to the queens challenge with a class named nQueens, which has two public member functions. The constructor at line nine is used to specify the…

Contents