@@ -120,29 +120,29 @@ def add_edge(
120
120
else :
121
121
self .adj_list [source_vertex ] = [destination_vertex ]
122
122
self .adj_list [destination_vertex ] = [source_vertex ]
123
- else : # For directed graphs
124
- # if both source vertex and destination vertex are present in adjacency
125
- # list, add destination vertex to source vertex list of adjacent vertices.
126
- if source_vertex in self .adj_list and destination_vertex in self .adj_list :
127
- self .adj_list [source_vertex ].append (destination_vertex )
128
- # if only source vertex is present in adjacency list, add destination
129
- # vertex to source vertex list of adjacent vertices and create a new vertex
130
- # with destination vertex as key, which has no adjacent vertex
131
- elif source_vertex in self .adj_list :
132
- self .adj_list [source_vertex ].append (destination_vertex )
133
- self .adj_list [destination_vertex ] = []
134
- # if only destination vertex is present in adjacency list, create a new
135
- # vertex with source vertex as key and assign a list containing destination
136
- # vertex as first adjacent vertex
137
- elif destination_vertex in self .adj_list :
138
- self .adj_list [source_vertex ] = [destination_vertex ]
139
- # if both source vertex and destination vertex are not present in adjacency
140
- # list, create a new vertex with source vertex as key and a list containing
141
- # destination vertex as it's first adjacent vertex. Then create a new vertex
142
- # with destination vertex as key, which has no adjacent vertex
143
- else :
144
- self .adj_list [source_vertex ] = [destination_vertex ]
145
- self .adj_list [destination_vertex ] = []
123
+ # For directed graphs
124
+ # if both source vertex and destination vertex are present in adjacency
125
+ # list, add destination vertex to source vertex list of adjacent vertices.
126
+ elif source_vertex in self .adj_list and destination_vertex in self .adj_list :
127
+ self .adj_list [source_vertex ].append (destination_vertex )
128
+ # if only source vertex is present in adjacency list, add destination
129
+ # vertex to source vertex list of adjacent vertices and create a new vertex
130
+ # with destination vertex as key, which has no adjacent vertex
131
+ elif source_vertex in self .adj_list :
132
+ self .adj_list [source_vertex ].append (destination_vertex )
133
+ self .adj_list [destination_vertex ] = []
134
+ # if only destination vertex is present in adjacency list, create a new
135
+ # vertex with source vertex as key and assign a list containing destination
136
+ # vertex as first adjacent vertex
137
+ elif destination_vertex in self .adj_list :
138
+ self .adj_list [source_vertex ] = [destination_vertex ]
139
+ # if both source vertex and destination vertex are not present in adjacency
140
+ # list, create a new vertex with source vertex as key and a list containing
141
+ # destination vertex as it's first adjacent vertex. Then create a new vertex
142
+ # with destination vertex as key, which has no adjacent vertex
143
+ else :
144
+ self .adj_list [source_vertex ] = [destination_vertex ]
145
+ self .adj_list [destination_vertex ] = []
146
146
147
147
return self
148
148
0 commit comments