title: How to return the n best shortest path (dijkstra algorithm)
body: <p>Hello I have implemented in C Dijkstra's algorithm to find the shortest path, but I need to return the n shortest paths, anyone have an idea how can I do.</p>
  
  <p>My dijkstra function:</p>
  
  <pre><code>int * Dijkstra(graph **g, int totalVertex, int vStart) {
    int i;
    int *distance = (int*) malloc(totalVertex * sizeof (int));
    int *last = (int*) malloc(totalVertex * sizeof (int));
    int *visited = (int*) calloc(totalVertex, sizeof (int));
    int maxDistance, m;
    graph *vertex;
  
    for (i = 0; i &lt; totalVertex; i++) {
      distance[i] = MAXINT;
      last[i] = -1;
    }
  
    distance[vOrigem] = 0;
  
    while (sum(visited, totalVertex) &lt; totalVertex) {
  
      maxDistance = MAXINT;
  
        for (i = 0; i &lt; totalVertex; i++) {
          if ((distance[i] &lt; maxDistance) &amp;&amp; (visited[i] == 0)) {
            maxDistance = distance[i];
            m = i;
          }
         }
  
      vertex = g[m];
      while (vertex != NULL) {
        if ((vertex-&gt;distance + distance[m]) &lt; (distance[vertex-&gt; destination])) {
          distance[vertex-&gt;destination] = vertex-&gt;distance + distance[m];
          last[vertex-&gt;destination] = m;
        }
      vertex = vertice-&gt;next;
      }
    visited[m] = 1;
    }
    free(distance);
    free(visited);
    return last;
  }
  </code></pre>
  
  <p>I need to call eg 2 times this function and it returns, the two shortest paths in the graph.</p>
  
  <p>Thank you.</p>