QUESTION: (https://www.interviewbit.com/problems/next-pointer-binary-tree/)
Given a binary tree
struct TreeLinkNode {
TreeLinkNode *left;
TreeLinkNode *right;
TreeLinkNode *next;
}
Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.
Initially, all next pointers are set to NULL.
1
/ \
2 3
/
4
\
5
WHAT SHOULD BE THE OUTPUT FOR SUCH A CASE?
shouldn’t 4 be pointing to 5 and 5 to null?
code: https://ide.codingblocks.com/s/264382
how do i handle the case when next to 4 is not null,like what are the changes required in line 17,instead of null to make 4 point to 5 instead of null