public List vertexList ( ) { List vertices = new ArrayList ( edgeSet ( ) . size ( ) ) ; Object startVertex = vertexSet ( ) . iterator ( ) . next ( ) ; Object vertex = startVertex ; Object previousVertex = null ; Object nextVertex = null ; while ( nextVertex != startVertex ) { assert ( degreeOf ( vertex ) == 2 ) ; List edges = edgesOf ( vertex ) ; vertices . add ( vertex ) ; Edge edge = ( Edge ) edges . get ( 0 ) ; nextVertex = edge . oppositeVertex ( vertex ) ; if ( nextVertex == previousVertex ) { edge = ( Edge ) edges . get ( 1 ) ; nextVertex = edge . oppositeVertex ( vertex ) ; } previousVertex = vertex ; vertex = nextVertex ; } return vertices ; }
Returns a list of the vertices contained in this cycle . The vertices are in the order of a traversal of the cycle .