.:Pudge:. 0 Light Poster

I am having trouble printing the contents of a b-tree of order 'n'
in level order. I have looked at algorithms online, but they only cover trees that have nodes with only 2 children. Shouldn't it also be called recursively? No algorithm I found used recursion.

void addToQue(struct node *root)
{   queue<node *> que;
    node *traverse;
    while(root!=NULL)
    {
        que.push(root);
        traverse=que.front();
        que.pop();
        for(int m=0; m<traverse->count; m++)
        {
            cout << traverse->data[m]<< " ";
        }
        cout << traverse->data << "\n";
        for(int i=0; i<2*treeOrder+1; i++)
        {
            if(root->child[i]!=NULL)
            {
                que.push(root->child[i]);
            }
        }
        if(que.empty())
        {
            root=que.front();
            addToQue(root);
            que.pop();
        }
        else
        {
            root=NULL;
        }    
    }
    cout << endl;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.