예제 #1
0
        public void Kruskal()
        {
            int      i;
            Queue    Q = new Queue(this.m);
            DSStruct Z = new DSStruct(this.n);

            Result = new AdjacencyMatrix(n, m);
            for (i = 0; i < n; i++)
            {
                Z.MakeSet(i); //tworz eosobny zbior dla kazdego wierzcholka
            }

            //umieszczam w kolejce kolejne krawedzie grafu
            for (i = 0; i < m; i++)
            {
                Q.Push(edges[i]);
            }

            for (i = 1; i < n; i++)
            {
                do
                {
                    e = Q.front();
                    Q.Pop();
                } while ((Z.FindSet(e.v1) == Z.FindSet(e.v2)));
                Result.AddEdge(e);
                Z.UnionSets(e);
            }
        }
예제 #2
0
        public void Kruskal()
        {
            int      i;
            Queue    Q = new Queue(this.m);
            DSStruct Z = new DSStruct(this.n);

            Result = new AdjacencyList(n);

            for (i = 0; i < n; i++)
            {
                Z.MakeSet(i); //tworz eosobny zbior dla kazdego wierzcholka
            }

            //umieszczam w kolejce kolejne krawedzie grafu

            /*for (i = 0; i < m; i++)
             * {
             *  Q.Push(edges[i]);
             * }*/

            for (i = 0; i < n; i++)
            {
                for (p = getAList(i); p != null; p = p.next)
                {
                    e.v1     = i;
                    e.v2     = p.v;
                    e.weight = p.weight;
                    Q.Push(e);
                }
            }

            for (i = 1; i < n; i++)
            {
                do
                {
                    e = Q.front();
                    Q.Pop();
                } while ((Z.FindSet(e.v1) == Z.FindSet(e.v2)));
                Result.addEdge(e);
                Z.UnionSets(e);
            }
        }