用HashMap实现Java邻接列表

用HashMap实现Java邻接列表,java,Java,我正在尝试创建一个邻接列表类。我正试图用HashMap实现这一点。每个bucket指向一个列表列表,最后一个列表的大小为3。 不幸的是,我没能让它工作。任何帮助都将不胜感激。 我得到一个错误的代码行 uList.get(0)、add(v);uList.get(1).add(容量); uList.get(2)、add(flow) /*邻接列表*/ 公共类邻接列表 { MapadjList; //建造师 公共邻接列表(int V) { //0->[[v1,容量1,流量1],[v2,容量2,流量2],

我正在尝试创建一个邻接列表类。我正试图用HashMap实现这一点。每个bucket指向一个列表列表,最后一个列表的大小为3。 不幸的是,我没能让它工作。任何帮助都将不胜感激。 我得到一个错误的代码行

uList.get(0)、add(v);uList.get(1).add(容量); uList.get(2)、add(flow)

/*邻接列表*/
公共类邻接列表
{
MapadjList;
//建造师
公共邻接列表(int V)
{
//0->[[v1,容量1,流量1],[v2,容量2,流量2],…]
adjList=新HashMap();
对于(int i=1;inode)及其
//-当前容量(又名剩余流量)
//-电流
公共无效添加(整数u、整数v、整数容量、整数流量)
{
ArrayList uList=新的ArrayList();
System.out.println(“ul:+uList”);
uList.get(0).add(v);uList.get(1).add(容量);uList.get(2).add(流量);
adjList.put(u,uList);
}
//检索到u的子项列表的方法(u->v1、v2、v3,…)
公共阵列列表getEdge(int u)
{
返回adjList.get(u);
}
}
/* Adjacency list */
public class AdjacencyList
{
    Map< Integer, ArrayList<ArrayList<Integer>> > adjList;

    //Constructor
    public AdjacencyList(int V)
    {
        // 0 -> [ [v1,capacity1,flow1] , [v2,capacity2,flow2] , ...]
        adjList = new HashMap< Integer, ArrayList<ArrayList<Integer> >>();
        for(int i = 1; i<V+1; i++)
        {
            adjList.put(i, new ArrayList<ArrayList<Integer>>());
        }

    }

    // method for adding an edge (->node) with its 
    // - current capacity (aka remaining flow)
    // - current flow
    public void addEdge(int u, int v, int capacity, int flow)
    {
        ArrayList<ArrayList<Integer>> uList = new ArrayList<ArrayList<Integer>>();
        System.out.println("ul: " + uList);
        uList.get(0).add(v); uList.get(1).add(capacity); uList.get(2).add(flow);
        adjList.put(u, uList);

    }

    // method for retrieving a list of children to u (u->v1,v2,v3,...)
    public ArrayList<ArrayList<Integer>> getEdge(int u)
    {
        return adjList.get(u);
    }

}