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

        }

        public override object Current

        {

            get

            {

                if (current_elem >= gr.vertexData.Count)

                    return null;

                GEdge edge = null;

                switch (gr.type)

                {

                    case Graph_Type.TYPE_LIST:

                        {

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

                            //foreach (GEdge e in lst)

                            //    if (e.v_end == (int)gr.vertexData[current_elem])

                            //        edge = e;

                            edge = lst.Count == 0 || current_elem >= lst.Count ? null : lst[current_elem];

                            break;

                        }

                    case Graph_Type.TYPE_MATRIX:

                        {

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

                            break;

                        }

                }

                return edge;

            }

            set

            {

                current_elem = (int)value;

            }

        }

        public override void next()

        {

            if (current_elem >= gr.getEdgeCountForVertex(vertex_number) && gr.type == Graph_Type.TYPE_LIST)

                return;

            else if (current_elem+1 >= gr.V && gr.type == Graph_Type.TYPE_MATRIX)

                return;

            //while (true)

            //{

                current_elem++;

                if (gr.type == Graph_Type.TYPE_MATRIX)

                {

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

                        current_elem++;

                }

        }

        public override void begin()

        {

            //if (gr.type == Graph_Type.TYPE_MATRIX)

            //{

            //    MGraph mgraph = (MGraph)gr;

            if (gr.type == Graph_Type.TYPE_LIST)

            {

                LGraph lg = (LGraph)gr;

                List<GEdge> lst = (List<GEdge>)lg.links[vertex_idx];

                current_elem = 0;

            }

            else if (gr.type == Graph_Type.TYPE_MATRIX)

            {

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

                {

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

                    {

                        current_elem = i;

                        break;

                    }

                }

            }

            //}

            //else if (gr.type == Graph_Type.TYPE_LIST)

            //{

            //    LGraph lgraph = (LGraph)gr;

            //    List<GEdge> lst = (List<GEdge>)lgraph.links[vertex_idx];

            //    if (lst.Count != 0)

            //        current_elem = 0;

            //}

        }

        public override void end()

        {

            if (gr.type == Graph_Type.TYPE_LIST)

            {

                LGraph lg = (LGraph)gr;

                List<GEdge> lst = (List<GEdge>)lg.links[vertex_idx];

                current_elem = lst.Count - 1;

            }

            else if (gr.type == Graph_Type.TYPE_MATRIX)

            {

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

                {

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

                    {

                        current_elem = i;

                        break;

                    }

                }

            }

        }

    }

    class Edge_Iterator : Iterator

    {

        int num_beg;

        int num_end;

        GEdge start;

        System.Collections.ArrayList visited = new System.Collections.ArrayList();

        public Edge_Iterator(Graph g, int _num_beg, int _num_end) : base(g)

        {

            num_beg = _num_beg;

            num_end = _num_end;

               int idx1 = (int)gr.getVertex(num_beg);

               int idx2 = (int)gr.getVertex(num_end);