Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace DijkstrasExample
- {
- class Graphs
- {
- private Dictionary<string, Dictionary<string, int>> vertexes;
- public Graphs()
- {
- vertexes = new Dictionary<string, Dictionary<string, int>>();
- }
- public void AddEdge(string v1, string v2, int v3)
- {
- if (!vertexes.ContainsKey(v1))
- {
- vertexes.Add(v1, new Dictionary<string, int>());
- }
- vertexes[v1].Add(v2, v3);
- }
- static Graphs CreateGraph()
- {
- Graphs g = new Graphs();
- g.AddEdge("a", "b", 9);
- g.AddEdge("a", "x", 11);
- g.AddEdge("a", "2", 10);
- g.AddEdge("b", "b", 9);
- g.AddEdge("b", "x", 11);
- g.AddEdge("b", "2", 10);
- return g;
- }
- public void PrintGraph()
- {
- foreach (var entry in vertexes)
- {
- var vertexNeighbors = entry.Value;
- Console.Write(entry.Key + ": key : ");
- PrintVertices(vertexNeighbors);
- Console.WriteLine();
- }
- }
- public void PrintVertices(Dictionary<string, int> vertices)
- {
- foreach (var entry in vertices)
- {
- Console.Write(entry.Key + " " + entry.Value + " ");
- }
- }
- static void SeedTheGraph()
- {
- Graphs graphExample = CreateGraph();
- graphExample.PrintGraph();
- }
- static void Main(string[] args)
- {
- SeedTheGraph();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement