package kruskal; public class Graph { private final int DEFAULT_EDGE_COST = 1; private Vertex[] vertices = null; /*list of all vertices in the graph*/ private int totalVertices = 0; /*keeps count of vertices*/ private double[][] adjMatrix = null; /*keeps the edges of the graph using adjacency matrix*/ private int[] adjacentVertCount = null; /*keeps count of adjacent vertices for each vertex*/ public Graph(int maxVertices) { this.vertices = new Vertex[maxVertices]; /*initialize vertices array*/ this.adjMatrix = new double[maxVertices][maxVertices]; /*initialize adjacency matrix*/ this.adjacentVertCount = new int[maxVertices]; /*initialize adjacent vertices count*/ for(int i=0; i= 0){ ret[index++] = i; } } return ret; } //get adjacent vertex numbers for a given vertex public int[] getAdjacentVertexNumbers(Vertex vert){ return this.getAdjacentVertexNumbers(vert.getVertexNo()); } //get adjacent vertices for a given vertexNo public Vertex[] getAdjacentVertices(int vertexNo){ Vertex[] ret = new Vertex[this.adjacentVertCount[vertexNo]]; int index = 0; for(int i=0; i= 0){ ret[index++] = this.vertices[i]; } } return ret; } //get adjacent vertices for a given vertex public Vertex[] getAdjacentVertices(Vertex vert){ return this.getAdjacentVertices(vert.getVertexNo()); } //gets the edge/path cost from adjacency list for two given vertexNo public double getEdgeCost(int fromVertNo, int toVertNo){ return this.adjMatrix[fromVertNo][toVertNo]; } //gets the edge/path cost from adjacency list for two given vertices public double getEdgeCost(Vertex fromVert, Vertex toVert){ return this.getEdgeCost(fromVert.getVertexNo(), toVert.getVertexNo()); } //gets all vertices public Vertex[] getVertices(){ return this.vertices; } //returns all the edges of the graph //needed for edge traversing algorithms public Edge[] getAllEdges(){ int totalEdges = 0; for(int i=0; i= 0){ edges[index++] = new Edge(this.vertices[i], this.vertices[j], this.adjMatrix[i][j]); } } } return edges; } public Edge[] getAllBidirectionalEdges(){ int totalEdges = 0; for(int i=0; i= 0){ edges[index++] = new Edge(this.vertices[i], this.vertices[j], this.adjMatrix[i][j]); } } } return edges; } }