// Graph.java class Graph { // the matrix stores the edge information private int[][] matrix; // this stores the values being stored by this graph private Type[] values; // the size of the graph private int size; // set the graph as empty public Graph(int size) { matrix = new int[size][size]; this.size = size; for(int i = 0; i < size; i++) { for(int j = 0; j < size; j++) { matrix[i][j] = 0; } } // make space for the values (and ignore the cast warning) @SuppressWarnings("unchecked") Type[] values = (Type[]) new Object[size]; this.values = values; } // insert an edge public void insertEdge(int from, int to, int cost) { matrix[from][to] = cost; } // remove an edge public void removeEdge(int from, int to) { matrix[from][to] = 0; } // return the cost of an edge or 0 for none public int getCost(int from, int to) { return matrix[from][to]; } // add a node's data to the graph public void setValue(int node, Type value) { values[node] = value; } }