- Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGraph.java
More file actions
Latest commit
130 lines (102 loc) · 5.01 KB
/
Copy pathGraph.java
File metadata and controls
130 lines (102 loc) · 5.01 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
packagegraph;
/* Do not add or remove public or protected members, or modify the signatures of
* any public methods. Do not add or remove public classes.
*
* You may make changes that don't affect the API (much) as seen from outside
* the graph package:
* + You may make methods in GraphObj abstract, if you want different
* implementations in DirectedGraph and UndirectedGraph.
* + You may add bodies to abstract methods, modify existing bodies,
* or override inherited methods.
* + You may change parameter names, or add 'final' modifiers to parameters.
* + You may private and package private members.
* + You may add additional non-public classes to the graph package.
*/
/** Represents a general unlabeled graph whose vertices are denoted by
* positive integers. A graph may be directed or undirected. For
* an undirected graph, outgoing and incoming edges are the same.
* Graphs may have self edges, but no multi-edges (edges with the same
* end points).
*
* Edges in a Graph are ordered by the sequence in which they were added.
*
* @author Rafayel Mkrtchyan
*/
publicabstractclassGraph {
/** Returns the number of vertices in me. */
publicabstractintvertexSize();
/** Returns my maximum vertex number, or 0 if I am empty. */
publicabstractintmaxVertex();
/** Returns the number of edges in me. */
publicabstractintedgeSize();
/** Returns true iff I am a directed graph. */
publicabstractbooleanisDirected();
/** Returns the number of outgoing edges incident to V, or 0 if V is not
* one of my vertices. */
publicabstractintoutDegree(intv);
/** Returns the number of incoming edges incident to V, or 0 if V is not
* one of my vertices8u. */
publicabstractintinDegree(intv);
/** Returns outDegree(V). This is simply a synonym, intended for
* use in undirected graphs. */
publicfinalintdegree(intv) {
returnoutDegree(v);
}
/** Returns true iff U is one of my vertices. */
publicabstractbooleancontains(intu);
/** Returns true iff U and V are my vertices and I have an edge (U, V). */
publicabstractbooleancontains(intu, intv);
/** Returns a new vertex and adds it to me with no incident edges.
* The vertex number is always the smallest integer >= 1 that is not
* currently one of my vertex numbers. */
publicabstractintadd();
/** Add an edge incident on U and V. If I am directed, the edge is
* directed (leaves U and enters V). Assumes U and V are my
* vertices. Has no effect if there is already an edge from U to
* V. Returns U. */
publicabstractintadd(intu, intv);
/** Remove V, if present, and all adjacent edges. */
publicabstractvoidremove(intv);
/** Remove edge (U, V) from me, if present. */
publicabstractvoidremove(intu, intv);
/** Returns an Iteration over all vertices in numerical order. */
publicabstractIteration<Integer> vertices();
/** Return successor K of V, numbering from 0, or 0 if there
* is no such successor (or V is not a vertex). */
publicabstractintsuccessor(intv, intk);
/** Return predecessor K of V, numbering from 0, or 0 if
* there is no such predecessor. Assumes V is one of my vertices. */
publicabstractintpredecessor(intv, intk);
/** Return neighbor K of V, numbering from 0, or 0 if
* there is no such neighbor. Assumes V is one of my vertices.
* This is a synonym for successor(v, k). */
publicintneighbor(intv, intk) {
returnsuccessor(v, k);
}
/** Returns an iteration over all successors of V in the order the edges
* to them were added. Empty if V is not my vertex. */
publicabstractIteration<Integer> successors(intv);
/** Returns an iteration over all predecessors of V in the order the edges
* to them were added. Empty if V is not my vertex. */
publicabstractIteration<Integer> predecessors(intv);
/** Returns successors(V). This is a synonym typically used on
* undirected graphs. */
publicfinalIteration<Integer> neighbors(intv) {
returnsuccessors(v);
}
/** Returns an iteration over all edges in me. Edges are returned
* as two-element arrays (u, v), which are directed if the graph
* is. In fact, the same array is used for each, and modified by
* the next() method of the iteration. */
publicabstractIteration<int[]> edges();
/** Return true iff V is one of my vertices. */
protectedabstractbooleanmine(intv);
/** Throw exception if V is not one of my vertices. */
protectedabstractvoidcheckMyVertex(intv);
/** Returns a unique positive identifier for the edge (U, V), if it
* is present, or 0 otherwise. The value of edgeId(v0, v1) does
* not change while the edge is present. It is used in
* LabeledGraph to number edges so that their labels are easy to
* retrieve and set. */
protectedabstractintedgeId(intu, intv);
}