rendered paste body public void colorBacktracking() throws NoSuchVertexException {
Object[] vertices = (graph.vertexKeys()).toArray();
int v = 0;
while(v >= 0 && v < vertices.length) {
if(vertices[v]==null) {
throw new NoSuchVertexException("Bad vertex");
}
Integer currentColor = (Integer)graph.getVertexData(vertices[v]);
graph.addVertex(vertices[v],(Integer)currentColor.intValue()+1);
Collection neighbors = graph.neighborData(v);
Iterator neighItr = neighbors.iterator();
while(neighItr.hasNext()) {
Integer currNeigh = (Integer)neighItr.next();
while(currNeigh.intValue()==currentColor && currentColor
<= maxColor) {
graph.addVertex(vertices[v],(Integer)currentColor.intValue()+1);
}
}
if(currentColor.intValue() > maxColor) {
graph.addVertex(vertices[v],(Integer)new Integer(0));
}
if(currentColor.intValue() == 0) {
v--;
} else {
v++;
}
}