Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4e40c64

Browse files
Three Hundred - Forty-Four Commit: Implement directed-graph-demo
1 parent 87db7d9 commit 4e40c64

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

‎Section_12(Graphs)/(1)_graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def edges_print(self):
8585
def outdegree(self, v):
8686
count = 0
8787
for j in range(self._vertices):
88-
if self._adjacent_matrix[v][j] != 0:
88+
if notself._adjacent_matrix[v][j] != 0:
8989
count = count + 1
9090
return count
9191

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from graph import Graph
2+
3+
G = Graph(4)
4+
G.display_adjacent_matrix()
5+
print('Vertices:', G.vertex_count())
6+
print('Edges:', G.edge_count())
7+
G.edges_print()
8+
G.insert_edge(0,1)
9+
G.insert_edge(0,2)
10+
G.insert_edge(1,2)
11+
G.insert_edge(2,3)
12+
G.display_adjacent_matrix()
13+
print('Vertices:', G.vertex_count())
14+
print('Edges:', G.edge_count())
15+
G.edges_print()
16+
print('Edge 1 - 3', G.exist_edge(1,3))
17+
print('Edge 1 - 2', G.exist_edge(1,2))
18+
print('Indegree 2', G.indegree(2))
19+
print('Outdegree 2', G.outdegree(2))
20+
print('Graph Adjacency Matrix')
21+
G.display_adjacent_matrix()
22+
G.remove_edge(1,2)
23+
print('Graph Adjacency Matrix')
24+
G.display_adjacent_matrix()
25+
print('Edges between 1--2:', G.exist_edge(1,2))

‎Section_12(Graphs)/graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def edges_print(self):
3939
def outdegree(self, v):
4040
count = 0
4141
for j in range(self._vertices):
42-
if self._adjacent_matrix[v][j] != 0:
42+
if notself._adjacent_matrix[v][j] != 0:
4343
count = count + 1
4444
return count
4545

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /