Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 19th, 2010 | Syntax: None | Size: 0.75 KB | Hits: 48 | Expires: Never
Copy text to clipboard
  1.         public String newBFS()
  2.         {
  3.                 String output="";
  4.                 Vector<Integer> neighbors= new Vector<Integer>();
  5.                 Vector<Integer> nodeList= new Vector<Integer>();
  6.                 int compCount=0;
  7.  
  8.                 for (int i=0; i<visited.size(); i++)
  9.                 {       nodeList.clear();
  10.                         if (!getVisited(i))
  11.                         {  
  12.                                 compCount++;
  13.                                 nodeList.add(i);
  14.                                 setVisited(i);
  15.                                 System.out.println(i);
  16.                                 getNeighbors(i, neighbors);
  17.  
  18.                                 while (!neighbors.isEmpty())
  19.                                 {
  20.                                         if (!getVisited(neighbors.firstElement()))     
  21.                                         {
  22.                                                 nodeList.add(neighbors.firstElement());
  23.                                                 setVisited(neighbors.firstElement());
  24.                                                 neighbors.remove(0);
  25.                                         }
  26.                                         else
  27.                                                 neighbors.remove(0);
  28.                                 }
  29.  
  30.                                 output+="Component "+compCount+" has nodes: "+ nodeList+"\n";
  31.                         }
  32.  
  33.                 }
  34.                 return output;
  35.         }