public String breadthFirstTraversal(int paraStartIndex) {
CircleObjectQueue tempCircleObjectQueue = new CircleObjectQueue();
int tempNodes = collecionIntMatrix.getRows();
boolean[] tempvisit = new boolean[tempNodes];
String resultString = "";
tempvisit[paraStartIndex] = true;
tempCircleObjectQueue.enqueue(new Integer(paraStartIndex));
resultString += paraStartIndex;
Integer temptInteger = (Integer) tempCircleObjectQueue.dequeue();
while (temptInteger != null) {
int temptIndex = temptInteger.intValue();
for (int i = 0; i < tempNodes; i++) {
if (tempvisit[i]) {
continue;
} // Of if
if (collecionIntMatrix.getData()[temptIndex][i] == 0) {
continue;
} // Of if
tempvisit[i] = true;
resultString += i;
tempCircleObjectQueue.enqueue(new Integer(i));
} // Of for i
temptInteger = (Integer) tempCircleObjectQueue.dequeue();
} // Of while
return resultString;
}// Of breadthFirstTraversal
public static void breadthFirstTraversalTest() {
// Test an undirected graph.
int[][] tempMatrix = { { 0, 1, 1, 0 }, { 1, 0, 0, 1 }, { 1, 0, 0, 1 }, { 0, 1, 1, 0 } };
Graph tempGraph = new Graph(tempMatrix);
System.out.println(tempGraph);
String tempSequence = "";
try {
tempSequence = tempGraph.breadthFirstTraversal(2);
} catch (Exception ee) {
System.out.println(ee);
} // Of try.
System.out.println("The breadth first order of visit: " + tempSequence);
}// Of breadthFirstTraversalTest