func (g *Graph) AddEdge(k1, k2 int) {
	v1 := g.GetVertex(k1)
	v2 := g.GetVertex(k2)

	// return an error if one of the vertices doesn't exist
	if v1 == nil || v2 == nil {
		panic("not all vertices exist")
	}

	// Add a directed edge between v1 and v2
	if !v1.isAdjacenceWith(k2) {
		v1.Adjacencies = append(v1.Adjacencies, v2)
	}

	// If the graph is undirected, add a corresponding
	// edge back from v2 to v1, effectively making the
	// edge between v1 and v2 bidirectional
	if !g.directed && !v2.isAdjacenceWith(k1) {
		v2.Adjacencies = append(v2.Adjacencies, v1)
	}

}
// The AddEdge method adds an edge between two vertices in the graph
The AddEdge method adds an edge between two vertices in the graph
// The AddEdge method adds an edge between two vertices in the graph
func (g *Graph) AddEdge(k1, k2 int) {
	v1 := g.GetVertex(k1)
	v2 := g.GetVertex(k2)
	if v1 == nil || v2 == nil {
		panic("not all vertices exist")
	}
	if !v1.isAdjacenceWith(k2) {
		v1.Adjacencies = append(v1.Adjacencies, v2)
	}
	if !g.directed && !v2.isAdjacenceWith(k1) {
		v2.Adjacencies = append(v2.Adjacencies, v1)
	}
}
func ( g * Graph ) AddEdge ( k1 , k2 int ) { v1 := g . GetVertex ( k1 ) v2 := g . GetVertex ( k2 ) if v1 == nil || v2 == nil { panic ( " " ) } if ! v1 . isAdjacenceWith ( k2 ) { v1 . Adjacencies = append ( v1 . Adjacencies , v2 ) } if ! g . directed && ! v2 . isAdjacenceWith ( k1 ) { v2 . Adjacencies = append ( v2 . Adjacencies , v1 ) } }
The AddEdge method adds an edge between two vertices in the graph
The AddEdge method adds an edge between two vertices in the graph
// return an error if one of the vertices doesn't exist // Add a directed edge between v1 and v2 // If the graph is undirected, add a corresponding // edge back from v2 to v1, effectively making the // edge between v1 and v2 bidirectional