I am trying to implement an adjacency list in Swift, basically a collection of lists, or I guess a collection of mutable arrays. I wrote a Depth Search First implementation in Java for and I would like to write the same in Swift. This code of for the Graph representation. Any ideas of how to do this? Here is the code in Java if that helps:
public class Graph
{
private List<Integer>[] adj;
public Graph(int numberOfVertices)
{
adj = (List<Integer>[]) new List[numberOfVertices];
...
for(int i = 0; i < numberOfVertices; i++)
adj[i] = new ArrayList<Integer>();
}
Even knowing how to declare a variable that contains an array of mutable arrays would be great. I didn't find any information on how to do this in the book released by apple or the web.