/* * AdjListGraph.kt * * This is Dave Musicant's AdjListGraph.kt from Fall 2024, * which was ported by Dave from the Java code at * https://www.programiz.com/dsa/graph-adjacency-list. * * Modified lightly by Tanya Amert for Spring 2025. * * Illustrates an implementation of a Graph via adjacency lists. */ // Add an edge to the graph fun addEdge(am: MutableList>, s: Int, d: Int) { am[s].add(d) am[d].add(s) } // Print the graph fun printGraph(am: MutableList>) { for (i in 0.. ${am[i][j]}") } println() } } // Test out the graph code fun main() { // Create the graph val V = 5; val am = mutableListOf>() for (i in 0..()) } // Add edges addEdge(am, 0, 1) addEdge(am, 0, 2) addEdge(am, 0, 3) addEdge(am, 1, 2) printGraph(am) }