title: Recursive method using a graph changes it's state on all levels
body: <p>I try to solve a graph problem with a recursive method returning one correct solution but I wonder if it is possible to do so, because changing the state of a graph in one recursion level will change it on other levels since they refer to the same object. Is there any way to solve it?</p>
  
  <p>Here are my code samples:</p>
  
  <p>1) Nodes - here you can see that Nodes are binded creating edges</p>
  
  <pre><code>public class Node{
  
  private int visited;                        
  private int label;                          
  private int order;                          
  private int degree;                         
  private ArrayList &lt;Node&gt; neighbours;        
  ...
  }
  </code></pre>
  
  <p>2) Graph</p>
  
  <pre><code>public class Graph {
  
  private ArrayList &lt;Square&gt; graph;       
  private int graphSize;                          
  private int numOfVertices;  
  ...
  }
  </code></pre>
  
  <p>3) And the sketch of a method:</p>
  
  <pre><code>public boolean backTracking(int label, int moves, Graph graph){     
  
  // something here
  
  if(current.getVisited() != 1){
  
              // current is a next neighbor of a vertex
              if(backTracking(current.getLabel(),completedMoves, graph))
                  return true;
  }
  
  return false;
  </code></pre>