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 9f8973d

Browse files
Three Hundred - Forty-Six Commit: Implement weighted-directed-graph-demo
1 parent f31a3a5 commit 9f8973d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
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, 26)
9+
G.insert_edge(0,2, 16)
10+
G.insert_edge(1,2, 12)
11+
G.insert_edge(2,3, 8)
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))

0 commit comments

Comments
(0)

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