Help in depth first search of a graph in adjacency matrix

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2008
Posts: 11
Reputation: W@n is an unknown quantity at this point 
Solved Threads: 0
W@n W@n is offline Offline
Newbie Poster

Help in depth first search of a graph in adjacency matrix

 
0
  #1
Oct 25th, 2008
Hi, recently i am doing an assignment that require me to do a depth first search on a given graph. However, i cannot get the result i needed. Is there any wrong with my code? Can anyone help? thank in advance=D

My graph
  1.  
  2. 0 4
  3. / \ /
  4. 1 2 ---3 5
The depth first search result should be 0,1,2,3 but i can only get 0,1.

my code
  1.  
  2. public static void depthFirstRecurse(int v) {
  3.  
  4. //mark v as visit
  5. visited = new boolean[g.getGraphSize()];
  6. visited[v] = true;
  7.  
  8. System.out.print(v + " ");
  9.  
  10. for (int u = 1; u < g.getGraphSize(); u++) {
  11.  
  12. if (visited[u] == false && adjMatrix[u][v] == 1) {
  13.  
  14. depthFirstRecurse(u);
  15.  
  16. }
  17. return;
  18. }
  19.  
  20. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum


Views: 1553 | Replies: 0
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC