class AdjNode:
def __init__(self, data):
self.vertex = data
self.next = None
Size of the array will be the no. of the
# vertices "V"
class Graph:
def __init__(self, vertices):
self.V = vertices
self.graph = [None] * self.V
# Function to add an edge in an undirected graph
def add_edge(self, src, dest):
# Adding the node to the source node
node = AdjNode(dest)
#from here
node.next = self.graph[src]
self.graph[src] = node
#to here
node = AdjNode(src)
node.next = self.graph[dest]
self.graph[dest] = node
if __name__ == "__main__":
V = 5
graph = Graph(V)
graph.add_edge(0, 1)
graph.add_edge(0, 4)
graph.add_edge(1, 2)
graph.add_edge(1, 3)
graph.add_edge(1, 4)
graph.print_graph()
Я не понял отсюда до здесь часть в комментариях. Пожалуйста, объясни. Я даже попробовал python репетитор визуализатор. Хотя все остальное понял. Этот код со страницы geeksforgeeks https://www.geeksforgeeks.org/graph-and-its-representations/ Любая помощь будет оценена.