// // COMP102 // Example 6: Undirected Graph Class // // Paul E. Dunne 25/10/99 // public class Graph { // // Fields // private Object [][] matrix; // This will record the definition // of the Graph structure. // // N.B. Declaration as 2-D array of Object // so that the graph edges may be associated // with both primitive types (via Wrappers) and // Compound types. Typical instantiations might // be as Boolean (matrix[v][w] is TRUE if and // only if there is an edge between vertex v and // vertex w); Integer (so that the values stored // represent the `distance' separating two // vertices); String (so that edges are // associated with `text') // private int order; // The number of vertices in this Graph Instance. private int size; // The number of edges in this Graph Instance. // This value is dynmaically updated when // the effect of relevant Instance methods // results in a change in the size of the Graph. // private Object NonEdge = null; // It is useful to have a distinctive value that // can indicate if no edge is present between // {v,w} in the Graph. Here we give a default // setting to the null Object. In specific // instantiations, however, this could be set // appropriately depending on the application // used, e.g. as the Boolean FALSE if using the // basic Boolean representation above; as the // largest (smallest) possible Integer where // edges are associated with `distances'; as the // empty String ("") in a labelling context, etc. //***************************************************// // Constructor Definition // //***************************************************// // The single Constructor provided, allocates storage// // for an n-vertex Graph. // // The 2-dimensional array matrix[][] is configured // // so that it comprises n-1 rows, the k'th row (k