How do you print the all the edges of a graph with a given adjacency matrix in python? for example, if 0 is adjacent to 3 and 8, it should print: 0 3 0 8 without repetition I've been using Bfs but i don't know how to update the queue and current element.
This is my code so far
A = [[0, 1, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 1],
[0, 0, 0, 1, 1, 0],
[0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0]]
def edges(A):
visited = [False] * len(A)
queue = []
s = [0][0]
queue.append(s)
visited[s] = True
while len(queue) > 0:
s = queue.pop(0)
print(s)
for i in range(len(A)):
print(i)
for j in range(len(A[0])):
if A[i][j] == 1 and visited[s]== False:
queue.append([i][j])
visited[s] = True
print(edges(A))