8000 Changed method name. · pythonpeixun/practice-python@6a4820d · GitHub
[go: up one dir, main page]

Skip to content

Commit 6a4820d

Browse files
committed
Changed method name.
1 parent 9f1ce14 commit 6a4820d

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

graphs/dijkstra.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def add_edge(self, source, dest, weight):
1515
self.adjacency_list[source].append(Edge(dest, weight))
1616
self.adjacency_list[dest].append(Edge(source, weight))
1717

18-
def get_edge(self, vertex):
18+
def get_neighbor(self, vertex):
1919
for e in self.adjacency_list[vertex]:
2020
yield e
2121

@@ -43,7 +43,7 @@ def dijkstra(graph, source, dest):
4343
v_tuple = q.get()
4444
v = v_tuple[1]
4545

46-
for e in graph.get_edge(v):
46+
for e in graph.get_neighbor(v):
4747
candidate_distance = distances[v] + e.weight
4848
if distances[e.vertex] > candidate_distance:
4949
distances[e.vertex] = candidate_distance

graphs/directed_graph_list.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def get_vertex(self):
2828
for v in self.adjacency_list:
2929
yield v
3030

31-
def get_edge(self, vertex):
31+
def get_neighbor(self, vertex):
3232
"""
3333
Generator for returning the next vertex adjacent to the given vertex
3434
:param vertex:
@@ -60,7 +60,7 @@ def dfs(self):
6060
while to_visit:
6161
v = to_visit.pop()
6262

63-
for neighbor in self.get_edge(v):
63+
for neighbor in self.get_neighbor(v):
6464
if neighbor not in parents:
6565
parents[neighbor] = v
6666
to_visit.append(neighbor)
@@ -82,7 +82,7 @@ def bfs(self):
8282
while not to_visit.empty():
8383
v = to_visit.get()
8484

85-
for neighbor in self.get_edge(v):
85+
for neighbor in self.get_neighbor(v):
8686
if neighbor not in parents:
8787
parents[neighbor] = v
8888
to_visit.put(neighbor)
@@ -113,7 +113,7 @@ def contains_cycle(self):
113113
statuses[v] = STATUS_STARTED
114114
to_visit.append(v) # add to stack again to signal vertex has finished DFS
115115

116-
for u in self.get_edge(v):
116+
for u in self.get_neighbor(v):
117117
if u in statuses:
118118
if statuses[u] == STATUS_STARTED:
119119
contains_cycle = True
@@ -152,7 +152,7 @@ def topological_sort(self):
152152
statuses[v] = STATUS_STARTED
153153
to_visit.append(v) # add to stack again to signal vertex has finished DFS
154154

155-
for u in self.get_edge(v):
155+
for u in self.get_neighbor(v):
156156
if u not in statuses:
157157
to_visit.append(u)
158158

0 commit comments

Comments
 (0)
0