title: 5 queens on a 8x8 chess board
body: <p>I am trying to find the number of ways possible to set 5 queens on a chess board without them being able to attack each other. I have succeeded to find the first set. The problem is how would I be able to find the next set of positions for 5 queens. The procedure in my program is like this:</p>
  
  <ul>
  <li>Generate a vector of disallowed positions based on the current queens on the board  </li>
  <li>Loop through all the positions on the board  </li>
  <li>Check if the current position is one of the disallowed positions on the board  </li>
  <li>If it is not, return the position, add it to the vector of queens on the board and begin the process again  </li>
  </ul>
  
  <p>Continue until there is no more position available i.e. all the remaining positions are disallowed</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  const int BSIZE = 8;
  char chessBoard[BSIZE][BSIZE];
  
  struct qPos
  {
      qPos() : h(0), v(0), found(true) {}
      int h; //horizontal pos
      int v; //vertical pos
      bool found; //if position is available
  };
  
  qPos findNextQPos(vector&lt;qPos&gt; Qs);
  void fillBoard(vector&lt;qPos&gt; Qs);
  void print();
  vector&lt;qPos&gt; generateDisallowed(vector&lt;qPos&gt; Qs);
  bool isDisallowed(qPos nextPos, vector&lt;qPos&gt; disallowedPos);
  
  int main(int argc, char **argv){
      vector&lt;qPos&gt; QsOnBoard; //Position of all the queens on board
      qPos nextQ; //next possible position
      while (nextQ.found)
      {
          nextQ = findNextQPos(QsOnBoard);
          if (nextQ.found)
          {
              QsOnBoard.push_back(nextQ); //If the nextQ is available i.e. not disallowed, add it to the queens vector
          }
      }
      fillBoard(QsOnBoard); //Fill the board with queens positions
      print(); // print the board
      return 0;
  }
  
  qPos findNextQPos(vector&lt;qPos&gt; Qs) {
      // Generate disallowed positions based on all the queens on board
      vector &lt;qPos&gt; disallowedPos = generateDisallowed(Qs);
      qPos nextQ;
      for (size_t i = 0; i &lt; BSIZE; i++)
      {
          for (size_t j = 0; j &lt; BSIZE; j++)
          {
              nextQ.h = i;
              nextQ.v = j;
              if (!isDisallowed(nextQ, disallowedPos)) { //Check if next possible position is a disallowed position
                  //cout &lt;&lt; "Next available:\n" &lt;&lt; nextQ.h &lt;&lt; ", " &lt;&lt; nextQ.v &lt;&lt; endl;
                  return nextQ; // if it is avaible return the position, break the loop
              }
          }
      }
      nextQ.found = false; // No available position is found to return, found is set to false, return the position
      return nextQ;
  }
  </code></pre>
  
  <p>Rest of the source code where I have the other functions such as generate disallowed and isDisallowed and etc is on <a href="http://pastebin.com/MVnT90r8" rel="nofollow noreferrer">this pastebin</a>. I thought it would not be really related to the question and the code here should not be too long.</p>
  
  <p>The result of the first set looks like this: 
  <img src="https://i.stack.imgur.com/Gf92c.png" alt="enter image description here">
  So how should I continue in order to be able to find all solution sets? This is where I get stuck.</p>