Java List Create createEmptyAdjacencyList(int n)

Here you can find the source of createEmptyAdjacencyList(int n)

Description

Creates an empty graph represented as an adjacency list of size n

License

Open Source License

Parameter

Parameter Description
n The maximum number of nodes in the graph.

Declaration

public static List<List<Integer>> createEmptyAdjacencyList(int n) 

Method Source Code


//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;
    }
}

Related

  1. createDefaultGroup(String name, String prefabGroup, List nodes)
  2. createDefaultValueList(int capacity, T defaultValue)
  3. createDelimitedString(String rawListAsString)
  4. createDoubleList(double[] values)
  5. createDriverSheetNames(List driverBeans)
  6. createEmptyList(Class type)
  7. createEmptyListArray(int size)
  8. createEmptyListOfType(List original, boolean sameSize)
  9. createEntireInStatement(List values)