Please suggest error in this program for level order tree traversal : <p>Please suggest error in this program for level order tree traversal
I am getting an infinite loop all printing 1</p>

<p>Algorithm:</p>

<p>For each node, first the node is visited and then it’s child nodes are put in a FIFO queue.</p>

<p>printLevelorder(tree)</p>

<pre><code>1.Create an empty queue q
2.temp_node = root /*start from root*/
3.Loop while temp_node is not NULL
a) print temp_node-&gt;data.
b) Enqueue temp_node’s children (first left then right children) to q
c) Dequeue a node from q and assign it’s value to temp_node


#include&lt;iostream&gt;
</code></pre>

<p>This is the node for tree</p>

<pre><code>struct node
{
struct node *left;
int data;
struct node *right;
};
</code></pre>

<p>This is node for queue to hold the node of tree</p>

<pre><code>struct qnode
{
struct node *node;
struct qnode *next;
};

struct frontandrear
{
struct qnode *front;
struct qnode *rear;
};


struct node* newNode( int data )
{
struct node *new_node = (struct node*)malloc( sizeof( struct node ) );
new_node-&gt;data = data;
new_node-&gt;left = new_node-&gt;right = NULL;
return new_node;
}



void enQueue( struct frontandrear *fr, struct node* node )
{
struct qnode* new_node = (struct qnode*)malloc( sizeof( struct qnode ) );
new_node-&gt;node = node;

if (fr-&gt;rear == NULL)
    {
    new_node-&gt;next = NULL;
    fr-&gt;rear = new_node;
    fr-&gt;front = new_node;

    }
else
    {
    new_node-&gt;next = fr-&gt;rear;
    fr-&gt;rear = new_node;
    }
}

struct node* deQueue( struct frontandrear *fr )
{
if (fr-&gt;front == NULL)
    {
    return NULL;
    }
struct node* num = fr-&gt;front-&gt;node;
fr-&gt;front = fr-&gt;front-&gt;next;

if (fr-&gt;front == NULL)
    {
    fr-&gt;front = fr-&gt;rear = NULL;
    }
return num;
}

void printLevelOrder( struct node* root )
{
struct frontandrear *frontandrear = (struct frontandrear*)malloc( sizeof(     struct frontandrear ) );
frontandrear-&gt;front = frontandrear-&gt;rear = NULL;

struct node *temp = root;

while (temp != NULL)
    {
    printf( "%d\t", root-&gt;data );
    if (temp-&gt;left)
        enQueue( frontandrear, root-&gt;left );
    if (temp-&gt;right)
        enQueue( frontandrear, root-&gt;right );
    temp = deQueue( frontandrear );
    }
}


int main( )
{

struct node *root = newNode( 1 );
root-&gt;left = newNode( 2 );
root-&gt;right = newNode( 3 );
root-&gt;left-&gt;left = newNode( 4 );
root-&gt;left-&gt;right = newNode( 5 );

printf( "Level Order traversal of binary tree is \n" );
printLevelOrder( root );
}
</code></pre>
