Connect nodes of a binery tree at same Level

Write a function to connect all the adjacent nodes at the same level in a binary tree. Structure of the given Binary Tree node is like following.
struct node {
  int data;
  struct node* left;
  struct node* right;
  struct node* nextRight;
}
Initially, all the nextRight pointers point to garbage values. Your function should set these pointers to point next right for each node. You can use only constant extra space.
Consider this example for your solution:
1            
          /    \
        2        3       
       / \      /  \
      4   5    6    7    
     / \           / \
    8   9        10   11 
nextRight for node with value 9 will be 10 and not NULL. 

Comments

Popular posts from this blog