添加顶点使用ArrayList中以图形 [英] Adding vertices to graph using ArrayList
本文介绍了添加顶点使用ArrayList中以图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想补充创建顶点(SETA,组B)将存储店铺,为后期比较他们,我怎么过,我无法顶点添加到ArrayList两个ArrayList中。
I am trying to add create two ArrayList of vertices (setA, setB) which will store the stores for comparing them late how ever I am unable to add vertices to the arraylist.
这里是code
import java.util.*;
public class BipartiteGraph<Vertex> {
private String strName;
ArrayList<Vertex>[] vertexList;
public BipartiteGraph(){
vertexList = new ArrayList[2];
vertexList[0] = new ArrayList<Vertex>();
vertexList[1] = new ArrayList<Vertex>();
Scanner vertexInput = new Scanner(System.in);
int vertex;
vertex = vertexInput.nextInt();
for(int i = 0; i < 10; i++){
vertexList[0].add(vertexInput.nextInt());
}
}
}
此外,如果有人能指导我,如果我在正确的方向。
Also if someone could guide me if I am in the right direction.
推荐答案
您正试图 INT
变量添加到顶点<的容器/ code>的对象。假设,你的
顶点
有一个构造函数接受 INT
你应该宁愿使用:
You are trying to add int
variable into the container of Vertex
objects. Assuming, that your Vertex
has a constructor accepting int
you should rather use:
vertexList[0].add(new Vertex(vertexInput.nextInt()));
这篇关于添加顶点使用ArrayList中以图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文