I have this code I'm using for implementing BFS as given below :
for(int i = 0; i < adjList.length; i++)
{
if(adjList[i].get(0).name.equals(u.name))
{
for(Iterator <Vertex> it = adjList[i].iterator(); it.hasNext();)
{
Vertex node = it.next();
System.out.println("====="+node.name);
if(node.color.equals("WHITE"))
{
node.color = "GRAY";
node.distance = u.distance + 1;
node.pre = u;
Q.add(node);
}
}
u.color = "BLACK";
System.out.println();
}
}
I have implemented adjacency list using Lists of List using the following code :
ArrayList<Vertex> adjList[] = (ArrayList<Vertex>[])new ArrayList[size];
and the values stored inside the adjacency list are :
adjList[0].add(new Vertex("r"));
adjList[0].add(new Vertex("s"));
adjList[0].add(new Vertex("v"));
adjList[1].add(new Vertex("s"));
adjList[1].add(new Vertex("r"));
adjList[1].add(new Vertex("w"));
adjList[2].add(new Vertex("t"));
adjList[2].add(new Vertex("w"));
adjList[2].add(new Vertex("x"));
adjList[2].add(new Vertex("u"));
Inside the iterator loop, I need the object "node" to store every consecutive values except the first value, is it possible?
There are several ways to skip the first element of the iterator.
For example :