Skip to content

Commit 4e40c64

Browse files
committed
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

+1-1
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 not self._adjacent_matrix[v][j] != 0:
8989
count = count + 1
9090
return count
9191

+25
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

+1-1
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 not self._adjacent_matrix[v][j] != 0:
4343
count = count + 1
4444
return count
4545

0 commit comments

Comments
 (0)