-
Notifications
You must be signed in to change notification settings - Fork 0
/
testdirected.py
37 lines (30 loc) · 999 Bytes
/
testdirected.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
File: testdirected.py
Editor: Leigh Stauffer
Project 12
"""
from graph import LinkedDirectedGraph
# Create a directed graph using an adjacency list
g = LinkedDirectedGraph()
# Add vertices labeled A, B, and C to the graph and print it
g.addVertex("A")
g.addVertex("B")
g.addVertex("C")
print("Expect vertices ABC and no edges: \n" + str(g))
# Insert edges with weight 2.5 and print the graph
g.addEdge("A", "B", 2.5)
g.addEdge("B", "C", 2.5)
g.addEdge("C", "B", 2.5)
print("Expect same vertices and edges AB BC CB all with weight 2.5: \n" + str(g))
# Mark all the vertices
for vertex in g.vertices():
vertex.setMark()
# Print the vertices adjacent to vertex B
print("Expect vertices adjacent to B, namely C:")
v = g.getVertex("B")
for neighbor in g.neighboringVertices(v.getLabel()):
print(neighbor)
# Print the edges of vertex B
print("Expect edges incident to B, namely BC:")
for edge in g.incidentEdges(v.getLabel()):
print(edge)