Разработка абстрактного типа данных «Простой, статический граф», страница 15

        }

        public override object Current

        {

            get

            {

                GEdge edge = null;

                if (current_elem >= gr.vertexData.Count)

                    return null;

                switch (gr.type)

                {

                    case Graph_Type.TYPE_LIST:

                        {

                            List<GEdge> lst = (List<GEdge>)((LGraph)gr).links[current_elem];

                            foreach (GEdge e in lst)

                                if (e.v_end == vertex_number)

                                    edge = e;

                           // edge = lst.Count == 0 ? null : lst[vertex_idx];

                            break;

                        }

                    case Graph_Type.TYPE_MATRIX:

                        {

                            edge = ((MGraph)gr).matrix[current_elem, vertex_idx];

                            break;

                        }

                }

                return edge;

            }

            set

            {

                current_elem = (int)value;

            }

        }

        public override void next()

        {

            if (current_elem + 1 >= gr.vertexData.Count)

                return;

            while (true)

            {

                current_elem++;

                if (current_elem == gr.vertexData.Count)

                {

                    //begin();

                    break;

                }

                if ( gr.EdgeExists( (int)gr.vertexData[current_elem],vertex_number) )

                    break;

            }

        }

        public override void begin()

        {

            for (int i = 0; i < gr.V; i++)

            {

                if (gr.EdgeExists((int)gr.vertexData[i], vertex_number))

                {

                    current_elem = i;

                    break;

                }

            }

        }

        public override void end()

        {

            for (int i = gr.V-1; i > 0; i--)

            {

                if (gr.EdgeExists((int)gr.vertexData[i], vertex_number))

                {

                    current_elem = i;

                    break;

                }

            }

            }

        }

Листингкласса GEdge:

    class GEdge

    {

        public int v_beg;

        public int v_end;

        public int weight;

        public object data;

        public GEdge(int beg, int end)

        {

            v_beg = beg;

            v_end = end;

            weight = 0;

            data = null;

        }

    }

Листингкласса Task1:

class Task1<TypeWeight, TypeData>

    {

        private Graph<TypeWeight, TypeData> m_graf;

        private List<int> m_numbersVertex;

        private int m_outVertex;

        private int m_inVertex;

        private int[,] m_D, m_P;

        public Task1(Graph<TypeWeight, TypeData> graf, int outVertex, int inVertex)

        {

            m_graf = graf;

            m_numbersVertex = new List<int>();

            m_outVertex = outVertex;

            m_inVertex = inVertex;

            if (m_graf.IsVertex(m_outVertex) && m_graf.IsVertex(m_inVertex))

            {

                CalculateNumbersVertex();

                Calculate_W_and_P();

                CalculateSource();

            }

        }

        public Task1(Task1<TypeWeight, TypeData> T)

        {

            m_graf = T.m_graf;

            m_outVertex = T.m_outVertex;

            m_inVertex = T.m_inVertex;

            m_numbersVertex = new List<int>(T.m_numbersVertex);

            if (m_graf.IsVertex(m_outVertex) && m_graf.IsVertex(m_inVertex))

            {

                int n = m_graf.GetCountVertex();

                for (int i = 0; i < n; i++)

                {

                    for (int j = 0; j < n; j++)

                    {

                        m_D[i, j] = T.m_D[i, j];

                        m_P[i, j] = T.m_P[i, j];

                    }