ргр по алгоритмам и структурам данных. АиСД РГР, ключников. Разработка атд Простой граф
Скачать 135.4 Kb.
|
AbstractGraph.csusing System.Collections.Generic; using System; namespace АиСД_РГР { abstract class AbstractGraph { public bool Type; //true == M-граф, иначе - L-граф public bool Oriented; //true == ориентированный public bool Weighted; public List public int CurrentIndex; public int EdgesCount;//количество ребер public List public Edge internal abstract class IteratorAllEdges // итератор ребер { protected int I; protected int J; protected bool State; //0 - не установлен, 1 - установлен protected AbstractGraph public IteratorAllEdges(AbstractGraph { State = false; // ItGraph = g; I = 0; J = 0; } public static IteratorAllEdges MakeIt(AbstractGraph { if (g.Type == false) { var q = new LGraph return q; } else { var q = new MGraph return q; } } public abstract bool Beg(); public abstract bool End(); public abstract void Next(); public abstract Edge } internal abstract class IteratorOutEdge // итератор исходящих ребер { protected Vertex protected bool State; protected int J; protected AbstractGraph public IteratorOutEdge(Vertex { //ItVertex = v; State = false; J = 0; //ItGraph = g; } public static IteratorOutEdge MakeIt(Vertex { if (g.Type == false) { //IteratorOutEdge q; var q = new LGraph return q; } else { var q = new MGraph return q; } } public abstract bool Beg(); public abstract bool End(); public abstract void Next(); public abstract Edge } internal abstract class IteratorInputEdge // итератор входящих ребер { protected Vertex protected bool State; protected int J; protected int I; protected AbstractGraph public IteratorInputEdge(Vertex { State = false; //ItVertex = v; //ItGraph = g; I = 0; J = 0; } public static IteratorInputEdge MakeIt(Vertex { if (g.Type == false) { //IteratorOutEdge q; var q = new LGraph return q; } else { var q = new MGraph return q; } } public abstract bool Beg(); public abstract bool End(); public abstract void Next(); public abstract Edge } public class IteratorVertexes { private bool VS; private int CurrentCur; private AbstractGraph public IteratorVertexes(AbstractGraph { VS = false; iGG = g; CurrentCur = 0; } public Vertex { if (iGG.Vertexes.Count == 0) { VS = false; return null; } else { VS = true; CurrentCur = 0; return iGG.Vertexes[0]; } } public Vertex { if (iGG.Vertexes.Count == 0) { VS = false; return null; } else { VS = true; CurrentCur = iGG.Vertexes.Count - 1; return iGG.Vertexes[iGG.Vertexes.Count - 1]; } } public void Next()//++ { if (VS) CurrentCur++; if (CurrentCur >= iGG.Vertexes.Count) { VS = false; } } public Vertex { if (VS == false) return null; else { return iGG.Vertexes[CurrentCur]; } } } public AbstractGraph() { CurrentIndex = 0; Vertexes = new List Matrix = new Edge Oriented = false; Weighted = false; } public AbstractGraph(bool D, bool F) { Type = F; EdgesCount = 0; CurrentIndex = 0; Vertexes = new List Matrix = new Edge Oriented = D; } static public AbstractGraph { if (!F) { return new LGraph } else { return new MGraph } } static public void Clear(AbstractGraph { graph = null; } public Vertex { if (i >= Vertexes.Count) return null; return Vertexes[i]; } static public AbstractGraph { if (!F) { return new LGraph } else { return new MGraph } } public bool Directed() { return Oriented; } public float Saturation() { if (Oriented) { float koef = EdgesCount / ((float)(Vertexes.Count * (Vertexes.Count - 1))); return koef; } else { float koef = EdgesCount / ((float)(Vertexes.Count * (Vertexes.Count - 1)) / 2); Console.WriteLine("VertexesCount: " + Vertexes.Count); return koef; } } public int V() { return Vertexes.Count; } public int E() { return EdgesCount; } public abstract Edge public abstract bool DeleteVertex(Vertex public abstract Vertex public abstract bool DeleteEdge(Vertex } } |