0

```
void Graph::writeShortestPaths (int first, ostream& outfile)
{
for (int i = 0; i < n; i++)// each vertex
{
currentDistances[i] = 999999;
predecessors[i] = -1;
toBeChecked[i] = true;
}
currentDistances[first] = 0;
writeShortestPathsHeader (outfile, first);
int pass = 0;
while (moreShortestPathsToFind()) // see below
{
int minVertex = first; // index of closest of vertices remaining to be reached
toBeChecked[minVertex] = false;
for (int i = 0; i < n; i++)// each vertex i
{
if (distances[n * minVertex + i] != 999 && predecessors[i] == -1) // i hasn't been reached yet and it is reachable from the new minVertex
{
if (currentDistances[i] > distances[n * minVertex + i])// previous distance to i is larger than the distance via minVertex
{
currentDistances[i] = distances[n * minVertex + i];// distance via minVertex
predecessors[i] = minVertex;
toBeChecked[minVertex] = false;
// cant figure out how to set First!!!! At least not without out getttng a never ending while loop
}
}
}
writeShortestPathsIntermediate (outfile, pass, minVertex);
}
writeShortestPathsResults (outfile);
}
```

I'm getting frustrated, I can do this algorithm on paper. However, I cant get it to work in code. I can't seem to figure out how to jump the the next vertex with the shortest distance. Thanks for any help.