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 fc4af6d

Browse files
Three Hundred - Forty-Two Commit: Implement weighted-undirected-graph-demo
1 parent 1a652c5 commit fc4af6d

File tree

1 file changed

+23
-0
lines changed

1 file changed

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

0 commit comments

Comments
(0)

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