| 37 | |
| 38 | // Prints the vertex and adjacency list |
| 39 | printGraph(output = (value) => console.log(value)) { |
| 40 | // get all the vertices |
| 41 | const getKeys = this.AdjList.keys() |
| 42 | |
| 43 | // iterate over the vertices |
| 44 | for (const i of getKeys) { |
| 45 | // get the corresponding adjacency list |
| 46 | // for the vertex |
| 47 | const getValues = this.AdjList.get(i) |
| 48 | let conc = '' |
| 49 | |
| 50 | // iterate over the adjacency list |
| 51 | // concatenate the values into a string |
| 52 | for (const j of getValues) { |
| 53 | conc += j + ' ' |
| 54 | } |
| 55 | |
| 56 | // print the vertex and its adjacency list |
| 57 | output(i + ' -> ' + conc) |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | export { Graph } |