///////////////////////////////////////////////////////////////////////// // May 9, 2002: // The destination of the getComponentsFromPaths message has been // changed from ma to ma2. If you want to write the corresponding // method to be destructive, replacing the input array by the output // array, you may do so as long as you document what you are // doing. In this case you may leave the destination of the message // as ma if you want. import java.util.*; /** The test class for Assignment 5, CS 146, Sections 6 & 8 Spring 2002 */ public class A5 { /** Prints the name of each vertex in a collection of vertices. Terminates in midprinting if a nonvertex is found. @param d the collection */ public static void traverseVertexCollection(Collection d){ Iterator dit=d.iterator(); try { while (dit.hasNext()) { Vertex v=(Vertex) dit.next(); System.out.print(v.getName()+" "); } System.out.println(""); } catch(ClassCastException e) { System.err.println( "nonvertex found -- can't continue"); } } /** Traverses each component in a collection of components (collections of vertices). Terminates in midtraversal if a top-level element of the collection is not a collection. @param c the collection of components */ public static void traverseComponents(Collection c) { Iterator cit=c.iterator(); try { while (cit.hasNext()) { Collection d=(Collection) cit.next(); traverseVertexCollection(d); } } catch(ClassCastException e) { System.err.println( "bad component found -- can't continue"); } } /** the main test function @param args ignored */ public static void main(String[] args) { ArrayList alphaLabels=new ArrayList(26); String[] alphaArray = new String[26]; Random r=new Random(2); String alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; for (int i=0; i<26; i++) { alphaArray[i] = alpha.substring(i,i+1); alphaLabels.add(alphaArray[i]); } MatrixGraph ma=new MatrixGraph(alphaLabels); ListGraph la=new ListGraph(alphaLabels); for (int k=1; k<26; k++) for (int j=0; j