Пример #1
0
        public static GraphMatrixInc ConvertToMatrixInc(GraphList input)
        {
            GraphList from = new GraphList(1);

            from.Set(input);
            int sumc = 0;

            for (int i = 0; i < from.NodesNr; i++)
            {
                sumc += from.CountElem(i);
            }
            sumc = sumc / 2;
            GraphMatrixInc q = new GraphMatrixInc(from.NodesNr, sumc);
            int            c = 0;

            for (int i = 0; i < from.NodesNr; i++)//pobiera po kolei elementy, dodaje do matrixinc i usuwa z listy
            {
                for (int j = 0; j < from.NodesNr; j++)
                {
                    if (from.GetConnection(i, j))
                    {
                        q.MakeConnection(i, j, c);
                        c++;
                        from.RemoveConnection(i, j);
                    }
                    q.setWeight(i, j, input.getWeight(i, j));
                }
            }
            return(q);
        }