can you explain me the code i ammentioning

0 votes
asked Jul 6, 2018 by anam siddiqui
#Practical 1 : BFS
class Vertex:
    def __init__(self,n):

    def add_neighbors(self,v):
        if v not in self.neighbors:

class Graph:
    def add_vertex(self,vertex):
        if isinstance (vertex,Vertex) and not in self.vertices:
            return True
            return False
    def add_edge(self,u,v):
        if u in self.vertices and v in self.vertices:
            for key,value in self.vertices.items():
                if key==u:
                if key==v:
            return True
            return False

    def print_graph(self):
        for key in sorted(list(self.vertices.keys())):
                          print(key +str(self.vertices[key].neighbors)+""+str(self.vertices[key].distance))
    def bfs(self,vert):
                          for v in vert.neighbors:
                              self.vertices[v].distance=vert.distance + 1
                          while len(q)>0:

                              for v in node_u.neighbors:
                                  if node_v.color=='black':
                                      if node_v.distance > node_u.distance + 1:
                                          node_v.distance=node_u.distance + 1              

for i in range(ord('A'),ord('K')):

for edge in edges:

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.