title: 8 queens puzzle conflict checking
body: <p>I recently read up about the 8 queens problem and tried to solve it myself, in C++. I made a class called eq.h, an implementation file called eq.cpp, and a main.cpp.</p>
  
  <p>The thing that I'm not sure about is, how do I check for row, column, and diagonal conflicts? What I'm thinking is, to use a nested for loop for conflict checking. How can that be applied? I've created a valid() function for that purpose. Below is what I've got so far. </p>
  
  <p>1) eq.h</p>
  
  <pre><code>#ifndef 8QUEEN_H
  #define 8QUEEN_H
  
  #include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  
  using namespace std;
  
  class 8queen
  {
          public:
              8queen();
              ~8queen();
              int solve();//solve problem using next_permutation
              void display();
  
          private:
              bool valid();
              int queens[8]; //array to store 8 integers that represent 8 queens
  };
  #endif
  </code></pre>
  
  <p>2) eq.cpp</p>
  
  <pre><code>#include "eq.h"
  #include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  
  using namespace std;
  
  8queen::8queen()
  {
      for(int i=0;i&lt;0;i++)
      {
          queens[i]=i;
      }
  }
  
  8queen::~8queen()
  {
  
  }
  
  //using next_perm, return all possible positions of the queens
  int 8queen::solve()
  {
      int count=0;
      do{
          if(valid())
          {
              count++;
              display();
          }
      }
      while(next_permutation(queens,queens+8));
      return count;
  }
  
  //display the positions of the queens
  void 8queen::display()
  {
      for(int i=0; i&lt;0;i++)
      {
          cout&lt;&lt;queens[i]&lt;&lt;' ';
      cout&lt;&lt;endl;
      }
  }
  
  //check if position is valid or not
  bool 8queen::valid()
  {
      return true;
  }
  </code></pre>
  
  <p>3) main.cpp </p>
  
  <pre><code>#include "eq.h"
  #include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  
  using namespace std;
  
  int main()
  {
      8queen object;
  
  
      cout&lt;&lt;object.solve()&lt;&lt;endl;
  }
  </code></pre>