Node<T> temp = new Node<T>(x);
private BinNode<T> right;
public BinNode(BinNode<T> left, T value, BinNode<T> right)
public BinNode<T> GetLeft()
public BinNode<T> GetRight()
public void setValue(T value)
public void SetLeft(BinNode<T> left)
public void SetRight(BinNode<T> right)
return(this.left != null);
return(this.right != null);
return "( " + left + " " + value + " " + right + " )";
public Node(T value, Node<T> next)
public void setValue(T value)
public void setNext(Node<T> next)
return this.value + " " ;
public static BinNode<int> CreateBinaryTree(int[] values, int index = 0)
if (index >= values.Length)
BinNode<int> node = new BinNode<int>(values[index]);
node.SetLeft(CreateBinaryTree(values, 2 * index + 1));
node.SetRight(CreateBinaryTree(values, 2 * index + 2));
public static int With1(BinNode<int> root)
return With1(root.GetLeft()) + With1(root.GetRight()) + 1;
public static int With2(BinNode<int> root)
head = (int)(Math.Pow(index, round));
public static bool IsTowTimses(int num, int run = 0)
return IsTowTimses(num, 2);
return IsTowTimses(num, run * 2);
public static int LeftLayer(BinNode<int> root)
return LeftLayer(root.GetLeft()) + 1;
public static void PrintBinaryTreeX(BinNode<int> root)
Queue<BinNode<int>> queue = new Queue<BinNode<int>>();
BinNode<int> current = queue.Remove();
int l = With2(root) * LeftLayer(root);
for (int i = 0; i < l / Math.Pow(2, round); i++)
Console.Write(s + " " + current.GetValue() + " ");
if (index == (int)(Math.Pow(2, round)))
for (int i = 0; i < index; i++)
Console.Write(s + "/| ");
if (current.GetLeft() != null)
queue.Insert(current.GetLeft());
if (current.GetRight() != null)
queue.Insert(current.GetRight());
public static void Main()
for (int i = 0; i < a.Length; i++)
BinNode<int> t = CreateBinaryTree(a);