title: How to modify dijkstra algorithm to find all possible paths?
body: <p>I know that could be asked before already but I cannot find it.
  I need to modify below dijkstra algorithm which works good for finding
  shortest path between 2 nodes but I need to find all possible paths also.
  I know it should be relatively easy to do this but so far I don't have idea
  how to do this simplest way. I'm using directed weighted graph.</p>
  
  <pre><code>    class Dijkstra
      {
          private List&lt;Node&gt; _nodes;
          private List&lt;Edge&gt; _edges;
          private List&lt;Node&gt; _basis;
          private Dictionary&lt;string, double&gt; _dist;
          private Dictionary&lt;string, Node&gt; _previous;
  
          public Dijkstra(List&lt;Edge&gt; edges, List&lt;Node&gt; nodes)
          {
  
              Edges = edges;
              Nodes = nodes;
              Basis = new List&lt;Node&gt;();
              Dist = new Dictionary&lt;string, double&gt;();
              Previous = new Dictionary&lt;string, Node&gt;();
  
              // record node 
              foreach (Node n in Nodes)
              {
                  Previous.Add(n.Name, null);
                  Basis.Add(n);
                  Dist.Add(n.Name, double.MaxValue);
              }
          }
  
          /// Calculates the shortest path from the start
          ///  to all other nodes
          public void calculateDistance(Node start)
          {
              Dist[start.Name] = 0;
  
              while (Basis.Count &gt; 0)
              {
                  Node u = getNodeWithSmallestDistance();
                  if (u == null)
                  {
                      Basis.Clear();
                  }
                  else
                  {
                      foreach (Node v in getNeighbors(u))
                      {
                          double alt = Dist[u.Name] + getDistanceBetween(u, v);
                          if (alt &lt; Dist[v.Name])
                          {
                              Dist[v.Name] = alt;
                              Previous[v.Name] = u;
                          }
                      }
                      Basis.Remove(u);
                  }
              }
          }
  
          public List&lt;Node&gt; getPathTo(Node d)
          {
              List&lt;Node&gt; path = new List&lt;Node&gt;();
  
              path.Insert(0, d);
  
              while (Previous[d.Name] != null)
              {
                  d = Previous[d.Name];
                  path.Insert(0, d);
              }
  
              return path;
          }
  
      public Node getNodeWithSmallestDistance()
          {
              double distance = double.MaxValue;
              Node smallest = null;
  
              foreach (Node n in Basis)
              {
                  if (Dist[n.Name] &lt; distance)       
                  {
                      distance = Dist[n.Name];
                      smallest = n;
                  }
              }
  
              return smallest;
          }
  
  
          public List&lt;Node&gt; getNeighbors(Node n)
          {
              List&lt;Node&gt; neighbors = new List&lt;Node&gt;();
  
              foreach (Edge e in Edges)
              {
                  if (e.Origin.Equals(n) &amp;&amp; Basis.Contains(n))
                  {
                      neighbors.Add(e.Destination);
                  }
              }
  
              return neighbors;
          }
  
         public double getDistanceBetween(Node o, Node d)
          {
              foreach (Edge e in Edges)
              {
                  if (e.Origin.Equals(o) &amp;&amp; e.Destination.Equals(d))
                  {
                      return e.Distance;
                  }
              }
  
              return 0;
          }
  
  
          public List&lt;Node&gt; Nodes
          {
              get { return _nodes; }
              set { _nodes = value; }
          }
  
          public List&lt;Edge&gt; Edges
          {
              get { return _edges; }
              set { _edges = value; }
          }
  
          public List&lt;Node&gt; Basis
          {
              get { return _basis; }
              set { _basis = value; }
          }
  
          public Dictionary&lt;string, double&gt; Dist
          {
              get { return _dist; }
              set { _dist = value; }
          }
  
          public Dictionary&lt;string, Node&gt; Previous
          {
              get { return _previous; }
              set { _previous = value; }
          }
      }
  }
  
  static void Main(string[] args)
          {
  //Nodes initialisation goes here
  
  Dijkstra d = new Dijkstra(_edges, _nodes);
  d.calculateDistance(_dictNodes["A"]);
   List&lt;Node&gt; path = d.getPathTo(_dictNodes["C"]);
  }
  </code></pre>