예제 #1
0
파일: Graph.cs 프로젝트: quela/myprojects
 public void AddNode(Node node)
 {
     if (!this.currentGraph.ContainsKey(node.Name))
     {
         this.currentGraph.Add(node.Name, node);
     }
 }
예제 #2
0
        public static void Main()
        {
            Graph currentGraph = new Graph();

            Node firstNode = new Node("1");
            Node secondNode = new Node("2");
            Node thirdNode = new Node("3");
            Node fourthNode = new Node("4");
            Node fifthNode = new Node("5");
            Node sixthNode = new Node("6");

            List<Edge> edges = new List<Edge>();

            edges.Add(new Edge(firstNode, thirdNode, 5)); // 5
            edges.Add(new Edge(firstNode, secondNode, 4));
            edges.Add(new Edge(firstNode, fourthNode, 9));
            edges.Add(new Edge(secondNode, fourthNode, 2));
            edges.Add(new Edge(thirdNode, fourthNode, 20));
            edges.Add(new Edge(thirdNode, fifthNode, 7)); // 7
            edges.Add(new Edge(fourthNode, fifthNode, 8));
            edges.Add(new Edge(fifthNode, sixthNode, 12));
            // edges.Add(new Edge(firstNode, fifthNode, 4));

            HashSet<Edge> result = Graph.FindMinPath(edges);

            foreach (var edge in result)
            {
                Console.WriteLine(edge);
            }
        }