Here you can find the source of createEmptyAdjacencyList(int n)
Parameter | Description |
---|---|
n | The maximum number of nodes in the graph. |
public static List<List<Integer>> createEmptyAdjacencyList(int n)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { /**/* ww w. java 2s .c o m*/ * Creates an empty graph represented as an adjacency list of size n * @param n The maximum number of nodes in the graph. */ public static List<List<Integer>> createEmptyAdjacencyList(int n) { if (n < 0) throw new IllegalArgumentException("n cannot be negative; received: " + n); List<List<Integer>> graph = new ArrayList<>(n); for (int i = 0; i < n; i++) graph.add(new ArrayList<>()); return graph; } }