N-queens problem and Backtracking ~how to represent the node?
<p>I am trying to build a library for solving different constrained problems .
I tried first with 4-queens problem and I can't figure out how I can represent the node .
I mean I can do it without any tree classes (by dimensional arrays) but I wanna represent it as tree-structure problem .</p>

<p>the depth of a tree is always &lt;=4 </p>

<p>here is my code :
<pre>
class Node {
  Node []next ;
  int value;
  int depth;
  String name;
  Node(){
      next=null;
      value=0;
      depth=0;
      name=null;
  }
  Node(int value,int depth,String name){
      this.value=value;
      //this.next=child;
      this.depth=depth;
      this.name=name;
  }</p>

<p>class Tree{
    Node root;
    Stack stack;
    String[] vars={"Q1","Q2","Q3","Q4"};
    int[] domain={1,2,3,4};
    int count=0;
    Tree(){
        root=new Node();
        stack=new Stack();</p>

<pre><code>}
</code></pre>

<p>void start(){
       stack.push(root);
       count++;
       search(stack.pop(),0);
   }</p>

<p>boolean consistent(Node current){
    boolean flag=true;
    int n=current.getDepth();
        //need more
       return flag;
   }</p>

<code>private void search(Node current,int num) {

    if(num==3&amp;&amp;consistent(current)){
        System.out.println("solution !");
        num=0;
    }
    else{
        if(consistent(current)){
        Node child[]=new Node[4];
            for(int i=0;i&lt;4;i++)
                child[i]=new Node(domain[i],current.getDepth()+1,vars[num]);

        current.setNext(child);

        for(int i=3;i&gt;=0;i--)
            stack.push(child[i]);

        search(stack.pop(),num+1);

    }
    search(stack.pop(),num);
    }
}&lt;code&gt; 
</code></pre>
