Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Start node op 0 zetten
- startingNode.Distance = 0;
- // Alle nodes op oneindig zetten
- for (int i = 0; i < graph.Nodes.Count; i++)
- graph.Nodes[i].Distance = int.MaxValue;
- // Alle nodes nog niet gevisit
- for(int i = 0; i < graph.Nodes.Count; i++)
- graph.Nodes[i].ShortestPathKnown = false;
- while (true)
- {
- // De node met laagste afstandswaarde ophalen
- Node u = graph.Nodes.Where(n => !n.ShortestPathKnown).OrderBy(n => n.Distance).FirstOrDefault();
- // Uit de while loop als er geen nodes meer zijn
- if (u == null)
- break;
- u.ShortestPathKnown = true;
- // update interface
- DisplayGraph(startingNode);
- // Kijken of de de lijn hoort bij de node
- List<Edge> neigbhours = graph.Edges.Where(e => e.A == u).ToList();
- foreach (Edge neighbour in neigbhours)
- {
- Node n;
- // N is altijd b want je bent al bij de A kant
- n = neighbour.B;
- if (!n.ShortestPathKnown)
- {
- int distance = u.Distance + neighbour.Weight;
- if (distance < n.Distance)
- n.Distance = distance;
- }
- }
- // update interface
- DisplayGraph(startingNode);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement