This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Found this lying around in my code folder from when I was | |
// first playing with Swift. Consider it public domain. | |
struct Graph<T: Hashable> { | |
let directed: Bool | |
var adj = Dictionary<T, [T]>() | |
init(directed d: Bool) { | |
directed = d | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct GraphAM { | |
private var adjMatrix = [[Int?]]() | |
private var numberOfVertices: Int { | |
return adjMatrix.count | |
} | |
init(numberOfVertices: Int) { | |
adjMatrix = Array(repeating: Array(repeating: nil, count: numberOfVertices), count: numberOfVertices) | |
} | |