title: Can't create a list of elements linked by a "Parent"
body: <p>I'm trying to create a method (using the *A** algorithm) that solves a puzzle and returns the steps to that solution. The solution it's easy.. but I can't return the path to that.</p>
  
  <p>I used a list of Nodes and then every time a push back a new Node I set the parent pointing to the Node which new came;</p>
  
  <pre><code>list&lt;Node&gt; opened;
  list&lt;Node&gt; closed;
  
  Node current;
  
  opened.push_back(start);
  
  while( opened.size() !=0 )
  {
     current = getLowestCostPath(opened);
  
  
     if(IsSolution(current) == true)
         return opened;
  
     opened.remove(current);
  
     if( !Has(closed, current))
            closed.push_back(current);
  
  
     for( int i = 0; i &lt; static_cast&lt;int&gt;(current.GetBoard().capacity()); i++ ) 
     {   
     xx = current.GetBoard()[i].X();
     yy = current.GetBoard()[i].Y();
  
         for(int j = 0; j &lt; static_cast&lt;int&gt;(current.GetBoard().capacity()); j++) 
         {
              if( isMovable(current))
              {
                  //if found a new node
                  Node newNode = Node(newBoard);
                  Node *t = &amp;current;
  
                  if(!Has(opened, newNode ) &amp;&amp; !Has(closed, newNode ) )
                  {
                     newNode.SetParent(t);
                     opened.push_back(newPath);
                  }
              }
          }
      }
  }
  
  (..)
  </code></pre>
  
  <p>the class Node it's just this</p>
  
  <pre><code>class Node{
  
  public:
     std::vector&lt;Point&gt; board;
     Path *parent;
  
     Node();
     Node(std::vector&lt;Point&gt; board)
  
     virtual std::vector&lt;Point&gt; GetBoard() const;
     virtual Path* GetParent() const;
     virtual void SetParent(Node *p); 
  </code></pre>
  
  <hr>
  
  <pre><code>Node::Node(): board(),parent(NULL)
  {
  }
  
  std::vector&lt;Point&gt; Node::GetBoard() const
  {
  return board;
  }
  
  void Path::SetParent(Node *p)
  {
      this-&gt;parent = p;
  }
  
  Path* Path::GetParent() const
  {
      return parent;
  }
  </code></pre>
  
  <p>But then I realized that I can't BUILD the path to solve the puzzle...</p>
  
  <p>I can't even see a single Parent board...</p>
  
  <pre><code>for( list&lt;Node&gt;::iterator it = goal.begin(); it != goal.end(); it++)
  {
      if( (*it).GetParent() != NULL ){
          cout &lt;&lt; "writing a board" &lt;&lt; endl;
          mas::WriteLine( (*it).GetParent()-&gt;GetBoard() , "\n");
      }
  }
  </code></pre>
  
  <p>I've searched all over the internet and I can't realize what am I doing wrong :(</p>
  
  <hr>
  
  <p><strong>I also tried this but it makes VS2005 Crash.</strong></p>
  
  <p>//goal it's the opened list that the method Solve returned....</p>
  
  <pre><code>for(std::list&lt;Node&gt;::iterator it = goal.end(); it-&gt;GetParent() != NULL; t-&gt;GetParent())
  {
  
      std::cout &lt;&lt; "step" &lt;&lt; std::endl;
      mas::WriteLine((*it).GetBoard(), "\n");
  }
  </code></pre>
  
  <hr>
  
  <p>I'm trying to be more clear and objective. So... see this parts</p>
  
  <pre><code>current = getLowestCostPath(opened);
  </code></pre>
  
  <p>The value returned by the method getLowestCostPath came from:</p>
  
  <pre><code>Node Solution::getLowestCostPath( std::list&lt;Node&gt; l)
  {
      std::list&lt;Node&gt;::reverse_iterator min = l.rbegin();
      int value = 0;
      for(std::list&lt;Node&gt;::reverse_iterator it = l.rbegin(); it != l.rend(); it++)
      {
          if( value &lt; (*it).GetStep())
          {   
              min = it;
              value = (*it).GetStep();
          }
      }
      return *min;
  }
  </code></pre>
  
  <p>after that... on the method Solve.. there is this part of the code</p>
  
  <pre><code>//if found a new node
  Node newNode = Node(newBoard);
  Node *t = &amp;current;
  
  newPath.SetParent(t);
  </code></pre>
  
  <p>I think that the ERROR it's on this part, <em>newPath</em> it's pointing to <em>t</em> when it should be pointing to node on the list <em>opened</em></p>
  
  <p>Is it true? If it is.. how can I fix this?</p>