using System.Collections.Generic;
public Node left, right, nextRight;
left = right = nextRight = null;
Queue<Node> q = new Queue<Node>();
for (int i = 0; i < n; i++)
public static void Main(String[] args)
BinaryTree tree = new BinaryTree();
tree.root = new Node(10);
tree.root.left = new Node(8);
tree.root.right = new Node(2);
tree.root.left.left = new Node(3);
Console.WriteLine("Following are populated nextRight pointers in "
+ "(-1 is printed if there is no nextRight)");
int a = tree.root.nextRight != null ? tree.root.nextRight.data : -1;
Console.WriteLine("nextRight of " + tree.root.data + " is "
int b = tree.root.left.nextRight != null ? tree.root.left.nextRight.data : -1;
Console.WriteLine("nextRight of " + tree.root.left.data + " is "
int c = tree.root.right.nextRight != null ? tree.root.right.nextRight.data : -1;
Console.WriteLine("nextRight of " + tree.root.right.data + " is "
int d = tree.root.left.left.nextRight != null ? tree.root.left.left.nextRight.data : -1;
Console.WriteLine("nextRight of " + tree.root.left.left.data + " is "