Skip to main content

Graph.add_edge

Add a directed edge into the graph

Usage

add_edge(v_from:int, v_to:int, weight:int = 1)

Parameters:
      v_from : int
            The origin vertice
      v_to : int
            The destination vertice
      weight : int
            The weight/cost of the edge

Example

from jellybeans.structures import Graphg = Graph()g.add_vertex(1)g.add_vertex(5)g.add_edge(1, 5, 19)print(g.to_adj_list()) # {1: [(5, 19)], 5: []}