public List <Vertex <T> > GetNeighbours(Vertex <T> vertex) { var neighbours = new List <Vertex <T> >(); if (this.adjacencyList.ContainsKey(vertex.GetIndex())) { foreach (var e in this.adjacencyList[vertex.GetIndex()]) { neighbours.Add(e.To); } } return(neighbours); }
public void CreateUnDirectedEdge(Vertex <T> from, Vertex <T> to, double weight = 1.0) { this.Vertices.Add(from); this.Vertices.Add(to); int index = from.GetIndex(); int index2 = to.GetIndex(); Edge <T> edge1 = new Edge <T>(weight, index2, from, to); Edge <T> edge2 = new Edge <T>(weight, index, to, from); if (this.adjacencyList.ContainsKey(index)) { this.adjacencyList[index].Add(edge1); } else { var edgeList = new List <Edge <T> >(); edgeList.Add(edge1); this.adjacencyList.Add(index, edgeList); } if (this.adjacencyList.ContainsKey(index2)) { this.adjacencyList[index2].Add(edge2); } else { var edgeList = new List <Edge <T> >(); edgeList.Add(edge2); this.adjacencyList.Add(index2, edgeList); } }