// Not valid, check this! public List <int> ShortestPath(DijkstraNode start, DijkstraNode end) { var visited = new HashSet <int>(); var pq = new PQ(); pq.Add(start); while (pq.Count() > 0) { var u = pq.GetMin(); if (visited.Contains(u.Id)) { continue; } visited.Add(u.Id); foreach (var n in u.Adjacent) { // to nie ma sensu if (u.Distance + n.Distance <= n.Distance) { n.Distance = u.Distance + n.Distance; } pq.AddOrUpdate(n); } } return(visited.ToList()); }
public void AddOrUpdate(DijkstraNode dn) { if (pq.ContainsKey(dn)) { pq.Remove(dn); } pq.Add(dn, true); }
public void Add(DijkstraNode n) => pq.Add(n, true);
public void Add(DijkstraNode dn) => Adjacent.Add(dn);