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

        {

            get

            {

                return orientation;

            }

        }

        public abstract bool InsertV(int num);

        public abstract bool DeleteV(int num);

        public abstract bool InsertE(int v_beg, int v_end);

        public abstract bool DeleteE(int v_beg, int v_end);

        public abstract int GetEdgeW(int v_beg,int v_end);

        public abstract void SetEdgeW(int v_beg, int v_end, int w);

        public abstract object getVertex(object criteria);

        public abstract bool EdgeExists(int beg, int end);

        public abstract void Update(PictureBox pic_box);

        public double K()

        {

          double k = ((double)E / ((double)V * ((double)V - 1.0)));

            if (orientation == Graph_Orientation.UNDIRECTED)

                k *= 2.0;

            return k;

        }

        public abstract Graph ConvertTo();

        public abstract void SetEdgeData(int v_beg, int v_end, object data);

        public abstract object GetEdgeData(int v_beg, int v_end);

        public abstract int getEdgeCountForVertex(int v_num);

    }

Листингитераторовребер:

  public abstract class Iterator

    {

        protected Graph gr;

        protected int current_elem;

        public Iterator(Graph g)

        {

            gr = g;

            current_elem = 0;

        }

        public abstract object Current

        {

            get;

            set;

        }

        public abstract void begin();

        public abstract void end();

        public abstract void next();

    }

    class Vertex_Iterator : Iterator

    {

        protected int start_idx;

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

        public override object Current

        {

            get

            {

                return current_elem;

            }

            set

            {

                current_elem = (int)value;

            }

        }

        public override void next()

        {

            double dist = -1;

            int best = -1;

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

                {

                    if (gr.EdgeExists((int)gr.vertexData[current_elem], (int)gr.vertexData[i]) && !visited.Contains(i) )

                    {

                        PointF pBegin = (PointF)gr.vertexCoords[current_elem];

                        PointF pEnd = (PointF)gr.vertexCoords[i];

                        double newdist = Math.Sqrt(Math.Pow(pEnd.X - pBegin.X, 2.0) + Math.Pow(pEnd.Y - pBegin.Y, 2.0));

                        if (dist > newdist)

                        {

                            dist = newdist;

                            best = i;

                        }

                        current_elem = i;

                        visited.Add(current_elem);

                       // break;

                    }

                }

        }

        public Vertex_Iterator(Graph g, int start_num): base(g)

        {

            //gr = g;

            //Current = 0;

            start_idx = current_elem = (int)g.getVertex(start_num);

            visited.Add(current_elem);

        }

        public override void begin()

        {

            Current = start_idx;

            visited.Clear();

            visited.Add(start_idx);

        }

        public override void end()

        {

            Current = gr.vertexData.Count - 1;

        }

    }

    class Outbox_Edge_Iterator : Iterator

    {

        int vertex_number;

        int vertex_idx;

        public Outbox_Edge_Iterator(Graph g, int num):base(g)

        {

            vertex_number = num;

            vertex_idx = (int)gr.getVertex(num);

                //MGraph mgraph = (MGraph)g;

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

                {

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

                    {

                        current_elem = i;

                        break;

                    }

                }