title: Floyd/Warshall Algorithm reconstructing a path, saving into a list
body: <p>Two simple questions and my brain's not working. I'm using Floyd's Algorithm and trying to reconstruct the path taken from vertex U to vertex V.
  Here's my code to reconstruct the path.</p>
  
  <pre><code>public List&lt;Integer&gt; findCheapestPath(int u, int v)
  {
      if (u &gt;= adjMatrix.length || v &gt;= adjMatrix.length || u &lt; 0 || v &lt; 0)
      {
          throw new IllegalArgumentException("Error--Illegal Arugment Exception: One of the verticies are not valid.");
      }
      int intermediate;
  
      intermediate = path[u][v];
      if (intermediate == -1)
      {
          pathList.add(u);
          return pathList;
      } else
      {
          findCheapestPath(u, intermediate);
          findCheapestPath(intermediate, v);
      }
      return pathList;
  }
  </code></pre>
  
  <p>For one example, let u = 0 and v = 3, and let the shortest path from 0 to 3 be 0,1,2,3.
  However I have two problems. My pathList is an instance variable of the class and:</p>
  
  <ol>
  <li>I want the list to return "0,1,2,3" but it only returns "0,1,2", or if i replace pathList.add(u) with pathList.add(v), then it returns
  only "1,2,3" I could not figure out how to make it return the entire
  path including both end vertices. trying to put pathList.add(other
  vertex) will cause it to duplicate every intermediate vertex.</li>
  <li>When I call the method again, letting u = 3 and v = 0, and let the shortest path from 3 to 0 be "3,0" (already the shortest path), it
  just adds onto my previous list making it <em>with my error from above</em>
  "0,1,2,3" or "1,2,3,0" when it's supposed to be just "3,0"</li>
  </ol>
  
  <p>Any help?</p>