static void BFS(int n) { Node ptr; int possibleNode; Q.Enqueue(n); // Save the initial node while ( ! Q.isEmpty() ) { possibleNode = Q.Dequeue(); // Examine next node if ( ! visited[ possibleNode ] ) { System.out.print(" " + possibleNode); visited[possibleNode] = true; possibleNode]; ptr != null; ptr = ptr.next ) { for ( ptr = adjacent[ if ( ! visited[ ptr.NodeID ] ) Q.Enqueue(ptr.NodeID); // Fan out from // this node first } } } }
static void BFS(int n)
Q.Enqueue(n); // Save the initial node
while ( ! Q.isEmpty() )
{
possibleNode = Q.Dequeue(); // Examine next node
if ( ! visited[ possibleNode ] )
System.out.print(" " + possibleNode);
possibleNode]; ptr != null; ptr = ptr.next ) {
[
if ( ! visited[ ptr.NodeID ] )
Q.Enqueue(ptr.NodeID); // Fan out from
// this node first
}
B L O G F A . C O M