The below program uses Binary Search Tree implementation
and Queue implementation
public void BFS()
{
Queue queue=new Queue();
Processable info;
TreeNode temp,temp1;
if(root!=null)
{
queue.enqueue(root);
}
while(true)
{
if(queue.isEmpty())
break;
temp=(TreeNode)queue.dequeue();
info=(Processable)temp.data;
info.process();
temp1=temp.left;
if(temp1!=null)
queue.enqueue(temp1);
temp1=temp.right;
if(temp1!=null)
queue.enqueue(temp1);
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment