-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeightedGraphInterface.java
54 lines (42 loc) · 1.93 KB
/
WeightedGraphInterface.java
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
//----------------------------------------------------------------------------
// WeightedGraphInterface.java by Dale/Joyce/Weems Chapter 9
//
// Interface for a class that implements a directed graph with weighted edges.
// Vertices are objects of class T and can be marked as having been visited.
// Edge weights are integers.
// Equivalence of vertices is determined by the vertices' equals method.
//
// General precondition: Except for the addVertex and hasVertex methods,
// any vertex passed as an argument to a method is in this graph.
//----------------------------------------------------------------------------
import Queue.UnboundedQueueInterface;
public interface WeightedGraphInterface<T>
{
boolean isEmpty();
// Returns true if this graph is empty; otherwise, returns false.
boolean isFull();
// Returns true if this graph is full; otherwise, returns false.
void addVertex(T vertex);
// Preconditions: This graph is not full.
// Vertex is not already in this graph.
// Vertex is not null.
//
// Adds vertex to this graph.
boolean hasVertex(T vertex);
// Returns true if this graph contains vertex; otherwise, returns false.
void addEdge(T fromVertex, T toVertex, int weight);
// Adds an edge with the specified weight from fromVertex to toVertex.
int weightIs(T fromVertex, T toVertex);
// If edge from fromVertex to toVertex exists, returns the weight of edge;
// otherwise, returns a special “null-edge” value.
UnboundedQueueInterface<T> getToVertices(T vertex);
// Returns a queue of the vertices that are adjacent from vertex.
void clearMarks();
// Sets marks for all vertices to false.
void markVertex(T vertex);
// Sets mark for vertex to true.
boolean isMarked(T vertex);
// Returns true if vertex is marked; otherwise, returns false.
T getUnmarked();
// Returns an unmarked vertex if any exist; otherwise, returns null.
}