예제 #1
0
        public override void AddEdge(Vertex a, Vertex b, int distance)
        {
            if (a.Equals(b))
            {
                Console.WriteLine("Cannot add adjacency to itself!");
                return;
            }
            a.AdjacentVertices.Add(new Adjacency(b, distance));

            //Replaces original with the updated vertex
            MyGraph[MyGraph.FindIndex(x => x.VertexID == a.VertexID)] = a;
        }
예제 #2
0
        public override void RemoveEdge(Vertex a, Vertex b)
        {
            //Index for where the vertex is in the graph
            var graphIndexA = MyGraph.FindIndex(x => x.VertexID == a.VertexID);
            var graphIndexB = MyGraph.FindIndex(x => x.VertexID == b.VertexID);

            //Index for where the adjacency is located
            var AdjIndexA = MyGraph[graphIndexA].AdjacentVertices.FindIndex(x => x.AdjacentVertex.VertexID == b.VertexID);
            var AdjIndexB = MyGraph[graphIndexB].AdjacentVertices.FindIndex(x => x.AdjacentVertex.VertexID == a.VertexID);

            MyGraph[graphIndexA].AdjacentVertices.Remove(MyGraph[graphIndexA].AdjacentVertices[AdjIndexA]);
            MyGraph[graphIndexB].AdjacentVertices.Remove(MyGraph[graphIndexB].AdjacentVertices[AdjIndexB]);
        }
예제 #3
0
 public override void SetVertexValue(Vertex a, string newValue)
 {
     a.VertexID = newValue;
     MyGraph[MyGraph.FindIndex(x => x.VertexID == a.VertexID)] = a;
 }