Adobe Interview Question
bfs using stack i think we can implement the queue using the two stack using taht concept we can implement the BFS with the stack
if a tree is N-ary tree
#define N 100
struct node
{
int item;
struct node *child[N]
}root;
where N can be any given random number
void BfsTraversal(struct node *root)
{
struct node *temp;
enquee(root);
while(!isEmpty())
{
temp=Dequee();
printf("%d",temp->value);
if(temp->left)
Enquee(temp->left);
if(temp->right)
Enquee(temp->right);
}
}
We just need an implementation of queue using 2 stacks.
- Rohan July 25, 2011