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

               foreach ( GEdge edge in (List<GEdge>)((LGraph)g).links[idx1] )

                   if (edge.v_end == num_end)

                   {

                       start = edge;

                       visited.Add(edge);

                   }

           }

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

           {

               start = ((MGraph)g).matrix[idx1, idx2];

               visited.Add(((MGraph)g).matrix[idx1, idx2]);

           }

        }

        public override void next()

        {

            //if (visited.Count-1 >= gr.E)

            //    return;

            switch (gr.type)

            {

                case Graph_Type.TYPE_LIST:

                    {

                        LGraph lg = (LGraph)gr;

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

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

                        int i = 0;

                        bool found = false;

                        while (!found)

                        {

                            for (i = 0; i < lst.Count; i++)

                                if (lst[i].v_end == num_end)

                                    break;

                            i++;

                            if (i >= lst.Count)

                            {

                                if ((int)lg.getVertex(num_beg) == lg.vertexData.Count - 1)

                                    return;

                                num_beg = (int)lg.vertexData[(int)lg.getVertex(num_beg) + 1];

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

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

                                if (lst.Count > 0)

                                {

                                    num_end = lst[0].v_end;

                                    found = true;

                                }

                            }

                            else

                            {

                                num_end = lst[i].v_end;

                                found = true;

                            }

                        }

                        break;

                    }

                case Graph_Type.TYPE_MATRIX:

                    {

                        bool found = false;

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

                        while (!found)

                        {

                            int i = 0;

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

                            {

                                MGraph mg = (MGraph)gr;

                                if (gr.EdgeExists(num_beg, (int)gr.vertexData[i])  && !visited.Contains(mg.matrix[idx, i]) )

                                {

                                    num_end = (int)gr.vertexData[i];

                                    visited.Add(mg.matrix[idx, i]);

                                    found = true;

                                    break;

                                }

                                if(!visited.Contains(mg.matrix[idx, i]))

                                visited.Add(mg.matrix[idx, i]);

                            }

                            if (!found)

                            {

                                if (idx == gr.vertexData.Count - 1) return;

                                num_beg = (int)gr.vertexData[++idx];

                                i = 0;

                            }

                        }

                        break;

                    }

            }

        }

        public override void begin()

        {

            if (gr.type == Graph_Type.TYPE_LIST)

            {

                LGraph lg = (LGraph)gr;

                int i = 0;

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

                while (lst.Count == 0)

                {

                    i++;

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