/** * Walk objects can be used to build walks from Graph objects. *
A Walk is simply a list of vertices in the order in which they occur in the walk. The edges are not listed. *
If the walk is closed, the first and last vertex will be the same, * and will end up being counted twice. *
Note that this class does not verify the validity of the walk, * i.e. it does not verify whether there are valid edges between two * adjacent vertices in the walk. *
DO NOT MODIFY THIS CLASS * @author Sophie Quigley * */ public class Walk { /** * Marker for no vertex. */ public static final int NOVERTEX = -1; /** * Maximum number of vertices in the walk. */ int maxV = 0; /** * Actual number of vertices in walk. */ int totalV = 0; /** * The vertices are listed in their order of traversal. *
Edges are not stored in this representation of walks. */ int[] vertices = null; /** * Creates a new empty Walk with room for a specified maximum number of vertices. * @param maxVertices maximum number of vertices in walk */ public Walk(int maxVertices) { maxV = (maxVertices<0) ? 0: maxVertices; vertices = new int[maxV]; clear(); } /** * Returns a String representation of the walk: * a list of the vertices separated by blanks. * @return The list of vertices in the walk separated by blanks * */ @Override public String toString() { String result = ""; for (int i=0; iNote that in closed walks the starting vertex will be counted twice. * @return The number of vertices in the walk * */ public int getTotalVertices() { return totalV; } /** * Gets the length of the walk, i.e. the number of edges in the walk. *
Note: empty and trivial walks both have a length of 0 * @return The number of edges in the walk * */ public int getLength() { return (totalV == 0) ? 0 : totalV - 1; } /** * Gets a specific vertex in the walk. * @param n The position of the vertex to be returned, starting at 0. * @return the vertex at position n in the walk * or Walk.NOVERTEX if the walk doesn't have n vertices. */ public int getVertex(int n) { return (n>=0 && n