Tree: Level Order Traversal

  • + 8 comments

    Can anyone tell me what is the problem here ?

    C solution :

    void levelOrder(node * root) {
        static int i=0;
        if(i==0){
            printf("%d ",root->data);
            i++;
        }
        if(root==NULL)
            return;
        if(root->left==NULL && root->right==NULL);
            return;
        if(root->left!=NULL)
            printf("%d ",root->left->data);
        if(root->right!=NULL)
            printf("%d ",root->right->data);
        levelOrder(root->left);
        levelOrder(root->right);    
    }
    

    Thanks!