@@ -61,14 +61,14 @@ public class DataStructures {
6161 private static Integer [] sorted = null ;
6262 private static String string = null ;
6363
64- private static int debug = 1 ; // Debug level. 0=None, 1=Time and Memory (if
64+ private static int debug = 0 ; // Debug level. 0=None, 1=Time and Memory (if
6565 // enabled), 2=Time, Memory, data structure
6666 // debug
67- private static boolean debugTime = true ; // How much time to: add all,
68- // remove all, add all items in
69- // reverse order, remove all
70- private static boolean debugMemory = true ; // How much memory is used by the
71- // data structure
67+ private static boolean debugTime = false ; // How much time to: add all,
68+ // remove all, add all items in
69+ // reverse order, remove all
70+ private static boolean debugMemory = false ; // How much memory is used by the
71+ // data structure
7272 private static boolean validateStructure = true ; // Is the data structure
7373 // valid (passed
7474 // invariants) and proper
@@ -1518,6 +1518,44 @@ private static boolean testGraph() {
15181518 if (debug > 1 )
15191519 System .out .println (pair .toString ());
15201520
1521+ // Prim on a graph with cycles
1522+ java .util .List <Vertex <Integer >> cyclicVerticies = new ArrayList <Vertex <Integer >>();
1523+ Graph .Vertex <Integer > cv1 = new Graph .Vertex <Integer >(1 );
1524+ cyclicVerticies .add (cv1 );
1525+ Graph .Vertex <Integer > cv2 = new Graph .Vertex <Integer >(2 );
1526+ cyclicVerticies .add (cv2 );
1527+ Graph .Vertex <Integer > cv3 = new Graph .Vertex <Integer >(3 );
1528+ cyclicVerticies .add (cv3 );
1529+ Graph .Vertex <Integer > cv4 = new Graph .Vertex <Integer >(4 );
1530+ cyclicVerticies .add (cv4 );
1531+ Graph .Vertex <Integer > cv5 = new Graph .Vertex <Integer >(5 );
1532+ cyclicVerticies .add (cv5 );
1533+
1534+ java .util .List <Edge <Integer >> cyclicEdges = new ArrayList <Edge <Integer >>();
1535+ Graph .Edge <Integer > ce1_2 = new Graph .Edge <Integer >(3 , cv1 , cv2 );
1536+ cyclicEdges .add (ce1_2 );
1537+ Graph .Edge <Integer > ce2_3 = new Graph .Edge <Integer >(2 , cv2 , cv3 );
1538+ cyclicEdges .add (ce2_3 );
1539+ Graph .Edge <Integer > ce3_4 = new Graph .Edge <Integer >(4 , cv3 , cv4 );
1540+ cyclicEdges .add (ce3_4 );
1541+ Graph .Edge <Integer > ce4_1 = new Graph .Edge <Integer >(1 , cv4 , cv1 );
1542+ cyclicEdges .add (ce4_1 );
1543+ Graph .Edge <Integer > ce4_5 = new Graph .Edge <Integer >(1 , cv4 , cv5 );
1544+ cyclicEdges .add (ce4_5 );
1545+
1546+ Graph <Integer > cyclicUndirected = new Graph <Integer >(cyclicVerticies , cyclicEdges );
1547+ if (debug > 1 )
1548+ System .out .println (cyclicUndirected .toString ());
1549+
1550+ start = cv1 ;
1551+ System .out .println (start .toString ());
1552+ if (debug > 1 )
1553+ System .out .println ("Prim's minimum spanning tree of a cyclic undirected graph from " + start .getValue ());
1554+ Graph .CostPathPair <Integer > cyclicPair = Prim .getMinimumSpanningTree (cyclicUndirected , start );
1555+ System .out .println (cyclicPair .toString ());
1556+ if (debug > 1 )
1557+ System .out .println (cyclicPair .toString ());
1558+
15211559 if (debug > 1 )
15221560 System .out .println ();
15231561 }
@@ -1590,8 +1628,7 @@ private static boolean testGraph() {
15901628 start = v1 ;
15911629 if (debug > 1 )
15921630 System .out .println ("Bellman-Ford's shortest paths of the undirected graph from " + start .getValue ());
1593- Map <Graph .Vertex <Integer >, Graph .CostPathPair <Integer >> map2 = BellmanFord
1594- .getShortestPaths (directed , start );
1631+ Map <Graph .Vertex <Integer >, Graph .CostPathPair <Integer >> map2 = BellmanFord .getShortestPaths (directed , start );
15951632 if (debug > 1 )
15961633 System .out .println (getPathMapString (start , map2 ));
15971634
0 commit comments