Today, I wrote a class Graph in python, for the purpose of implementing the following dfs and bfs:
Can use the tinyG.txt for input.
class Graph():
def __init__(self, filepath):
self.V = 0 #-- num of vertices
self.E = 0 #-- num of edges
self.adj = {}
self.filepath = filepath
fhand = open(self.filepath)
self.V = int(fhand.readline())
self.E = int(fhand.readline())
for i in range(0, self.E):
string = fhand.readline()
string = string.split(' ')
''' the two vertices was seperated by ' '. '''
v = int(string[0])
w = int(string[1])
'''if vertices was not created yet,'''
'''have to create a empty list for that vertice'''