-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathundirected_graph.rb
58 lines (43 loc) · 1.36 KB
/
undirected_graph.rb
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#lib/undirected_graph.rb
class UndirectedGraph
def initialize()
end
#accessor methods:
def vertices
end
def neighbors(vertex)
end
#if there is no edge throws and ArgumentError
def weight(vertex1, vertex2)
end
def degree(vertex)
end
def has_vertex?(vertex)
end
def has_edge?(vertex1, vertex2)
end
def size
end
#mutator methods:
#adds a vertex to the graph
#if a vertex is already in the graph, does nothing
#returns true iff a vertex was added (false if the vertex was already in the graph)
def add_vertex!(vertex)
end
#adds an edge with the given weight between two vertices, starting at vertex1 and pointing to the vertex2
#if there is already an edge with said weight, it updates the weight
#if either one (or both) of the vertices are not in the graph, it throws an ArgumentError
#also, if you're trying to make a self_loop, throws an error
def add_edge!(vertex1, vertex2, weight)
end
#removes a vertex and and edges associated with it
#if there is no such vertex in the graph, throws an ArgumentError
#returns a hash of the removed vertex's out_neighborhood
def remove_vertex!(vertex)
end
#removes an edge between two vertices (vertex1 <-> vertex2)
#returns the weight of the removed edge
#if there was no such edge (or either one of the vertices were not in the vertex, throws an ArgumentError)
def remove_edge!(vertex1, vertex2)
end
end