/* * AdjMatrixGraph.kt * * This is Dave Musicant's AdjMatrixGraph.kt from Fall 2024, * which was ported by Dave from the Java code at * https://www.programiz.com/dsa/graph-adjacency-matrix. * * Modified lightly by Tanya Amert for Spring 2025. * * Illustrates an implementation of a Graph via adjacency matrices. */ class AdjMatrixGraph(numVertices: Int) { var adjMatrix = Array>(numVertices) {Array(numVertices) {false}} // Add edges fun addEdge(i: Int, j: Int) { adjMatrix[i][j] = true adjMatrix[j][i] = true } // Remove edges fun removeEdge(i: Int, j: Int) { adjMatrix[i][j] = false adjMatrix[j][i] = false } // Print the matrix override fun toString(): String { var s = StringBuilder() for (i in 0..