public WeightedGraph CreateDummyGraph()
        {
            WeightedGraph graph = new WeightedGraph();

            graph.vertices = 4;
            graph.edges    = new List <WGraphEdge>();
            WGraphNode a = new WGraphNode();

            a.data = 1;
            WGraphNode b = new WGraphNode();

            b.data = 1;
            WGraphNode c = new WGraphNode();

            c.data = 1;
            WGraphNode d = new WGraphNode();

            d.data = 1;

            WGraphEdge edge = new WGraphEdge();

            edge.source      = a;
            edge.destination = b;
            edge.weight      = 10;
            graph.edges.Add(edge);

            edge             = new WGraphEdge();
            edge.source      = a;
            edge.destination = c;
            edge.weight      = 5;
            graph.edges.Add(edge);

            edge             = new WGraphEdge();
            edge.source      = a;
            edge.destination = d;
            edge.weight      = 6;
            graph.edges.Add(edge);

            edge             = new WGraphEdge();
            edge.source      = b;
            edge.destination = c;
            edge.weight      = 15;
            graph.edges.Add(edge);

            edge             = new WGraphEdge();
            edge.source      = c;
            edge.destination = d;
            edge.weight      = 4;
            graph.edges.Add(edge);

            return(graph);
        }
        public void KruskalsMST(WeightedGraph graph)
        {
            //Sort all edges by their weight
            SortEdges(graph.edges);
            //Loop
            //  If no cycle formed then include in MST with Union Find
            //  Else move on to next edge
            WGraphEdge[] parent = new WGraphEdge[graph.vertices];
            int          index  = 0;

            while (index < graph.edges.Count)
            {
            }
        }
        private void btnAddEdge_Click(object sender, EventArgs e)
        {
            try
            {
                int[] input = SearchForm.ConvertToIntArray(txtConnectVertices.Text.Trim().Split(','));
                nodes = nodes ?? new List <WGraphNode>();
                WGraphNode source = FindNode(input[0]);
                if (source == null)
                {
                    source      = new WGraphNode();
                    source.data = input[0];
                    nodes.Add(source);
                }

                WGraphNode destination = FindNode(input[1]);
                if (destination == null)
                {
                    destination      = new WGraphNode();
                    destination.data = input[1];
                    nodes.Add(destination);
                }

                WGraphEdge edge = new WGraphEdge();
                edge.source      = source;
                edge.destination = destination;
                edge.weight      = Convert.ToInt32(txtWeight.Text);
                if (source.edges == null)
                {
                    source.edges = new List <WGraphEdge>();
                }
                source.edges.Add(edge);
                txtOperation.Text = "Operation Add Edge Successful";
            }
            catch (Exception ex)
            {
                MessageBox.Show("btnAddEdge_Click: " + ex.Message);
            }
        }
 public void UnionFind(WGraphEdge edge)
 {
 }