BFS || c++ || iterative || explanation || level order traversal
\nBasically this is purely level order travsersal code with slight modification for the  root -> next value \n\nYou just have to think 2 things in this question
\nBasically this is purely level order travsersal code with slight modification for the  root -> next value \n\nYou just have to think 2 things in this question.\n\n1.How to get the last val to NULL ?.\n2.How to get connect with the current node to previous one ?.\n\nIf you are able to find the ans of these two questions mentioned above then you will reach the solution \nalso if you are here to see the solution i would recommend you to pause for a while \nand think about these questions i am sure you willl find the ans otherwise ans \nis just right below you can see anytime you want just give it a though for a whlle.\n\n.\n.\n.\n.\n.\n.\n.\n```\nif(root == NULL) return NULL;\n        queue<Node*> q;\n        q.push(root);\n        while(!q.empty()){\n            int size = q.size(); // get size of queue \n            for(int i=0 ; i < size ; i++){\n                Node* item = q.front(); \n                if(size - 1 == i) // checking the last value of the level\n                     item -> next = NULL; \n                \n                q.pop();\n                \n                if(size - 1 != i) // if this is not the last value then previous value will point to next one\n                     item -> next = q.front(); \n                \n                if(item -> left != NULL)\n                    q.push(item -> left);\n                if(item -> right != NULL)\n                    q.push(item -> right);\n            }\n        } \n        return root; \n\t\t\n\n```\n**In an interview there will be a follow up question in which you might be asked to solve this question with recursion so better be prepared for this bomb !!!!**\n```\n\n\nBefore you see the solution as per rituals please please please think of a solution by yourself you might be right or wrong doesn\'t matter you fought hard with the question !!!\n\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n\n Node* connect(Node* root) {\n        if(root == NULL) return NULL;\n        \n        //now part-1 - connect Left node with right node\n        if(root->left!=NULL) root->left->next = root->right;\n        \n        //now part-2 - connect right node with next subtree left node\n        if(root->right!=NULL && root->next!=NULL) root->right->next = root->next->left;\n        \n        //Now do the same job for subtrees\n        connect(root->left); \n        connect(root->right);\n        \n        return root; \n        // every time return is made, but at last the same root is retured to main\n    }\n\n\n*** IF YOU LOVED THE SOLUTION PLEASE CLICK ON THE UPVOTE BUTTON ***\n\n\n\n\t\t
['Breadth-First Search', 'C', 'C++']