Results 1 to 2 of 2
Thread: how to get height of a BFS tree
- 11-23-2011, 05:27 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 9
- Rep Power
- 0
how to get height of a BFS tree
This is my code that implements a directed graph.It prints the nodes in bfs order
but how can i get then the height of the corresponding tree?
thanks
Java Code:static void BFS(Vector<Vector<Integer>> g,int s){ Queue<Integer> q = new LinkedList<Integer>(); boolean[] visited=new boolean[g.size()]; for(int i=0;i<g.size();i++){ visited[i]=false; } q.offer(s); System.out.print(s); while(q.isEmpty()==false){ int u=q.remove(); if (visited[u]==false){ visited[u]=true; for ( int x=0;x<g.get(u).size();x++){ int v =g.get(u).get(x); q.offer(v); if(visited[v]==false) { System.out.print(" "+v); } } } } }
- 11-24-2011, 07:53 AM #2
Member
- Join Date
- Nov 2011
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
How do I determine the height of nodes in a AVL tree?
By ryuzog in forum New To JavaReplies: 2Last Post: 11-09-2010, 01:34 PM -
Width (-1) and height (-1) cannot be <= 0
By LovJava in forum AWT / SwingReplies: 5Last Post: 04-24-2010, 12:16 AM -
Data Structures(Binary Search Tree to AVL Tree)ASAP pls
By jfAdik in forum Forum LobbyReplies: 0Last Post: 04-04-2010, 07:40 AM -
height of the image.
By programmer_007 in forum Java 2DReplies: 13Last Post: 02-18-2010, 12:17 PM -
dynamising the height of a JPopupMenu
By iimasd in forum AWT / SwingReplies: 6Last Post: 11-21-2007, 10:01 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks