public static void Leaves(BinTreeNode <int> bt, Stack <BinTreeNode <int> > s)
 {
     if (bt != null)
     {
         if (bt.GetLeft() == null && bt.GetRight() == null)
         {
             s.Push(bt);
         }
         Leaves(bt.GetLeft(), s);
         Leaves(bt.GetRight(), s);
     }
 }
 public static int AmountOfLeaves(BinTreeNode <int> S)
 {
     if (S == null)
     {
         return(0);
     }
     if (S.GetLeft() == null && S.GetRight() == null)
     {
         return(1);
     }
     return(AmountOfLeaves(S.GetLeft()) + AmountOfLeaves(S.GetRight()));
 }
 public static int SumOfRightSons(BinTreeNode <int> S)
 {
     if (S == null)
     {
         return(0);
     }
     if (S.GetRight() != null)
     {
         return(S.GetRight().GetValue() + SumOfRightSons(S.GetLeft()) + SumOfRightSons(S.GetRight()));
     }
     return(SumOfRightSons(S.GetLeft()) + SumOfRightSons(S.GetRight()));
 }
 public static int SumOfEven(BinTreeNode <int> S)
 {
     if (S == null)
     {
         return(0);
     }
     if (S.GetValue() % 2 == 0)
     {
         return(1 + SumOfEven(S.GetLeft()) + SumOfEven(S.GetRight()));
     }
     return(SumOfEven(S.GetLeft()) + SumOfEven(S.GetRight()));
 }
 public static bool WholeTree(BinTreeNode <int> S)
 {
     if (S == null)
     {
         return(false);
     }
     if (S.GetLeft() == null && S.GetRight() != null || S.GetLeft() != null && S.GetRight() == null)
     {
         return(false);
     }
     return(WholeTree(S.GetLeft()) && WholeTree(S.GetRight()));
 }
 public static int AmountOfTwoSons(BinTreeNode <int> S)
 {
     if (S == null)
     {
         return(0);
     }
     if (S.GetLeft() != null && S.GetRight() != null)
     {
         return(1 + AmountOfTwoSons(S.GetLeft()) + AmountOfTwoSons(S.GetRight()));
     }
     ;
     return(AmountOfTwoSons(S.GetLeft()) + AmountOfTwoSons(S.GetRight()));
 }
 public static int AmountOfVertices(BinTreeNode <int> S)
 {
     if (S == null)
     {
         return(0);
     }
     return(1 + AmountOfVertices(S.GetLeft()) + AmountOfVertices(S.GetRight()));
 }
 public static void AddBrother(BinTreeNode <int> S)
 {
     if (S.GetLeft() != null && S.GetRight() != null)
     {
         if (S.GetLeft() == null)
         {
             BinTreeNode <int> LeftB = new BinTreeNode <int>(0);
             S.SetLeft(LeftB);
         }
         if (S.GetRight() == null)
         {
             BinTreeNode <int> RightB = new BinTreeNode <int>(0);
             S.SetLeft(RightB);
         }
         AddBrother(S.GetLeft());
         AddBrother(S.GetRight());
     }
 }
 public static bool Halciuho(BinTreeNode <int> S)
 {
     if (S == null)
     {
         return(true);
     }
     if (AmountOfSingleSons(S) > 0)
     {
         return(false);
     }
     if (S.GetRight() != null && S.GetLeft() != null)
     {
         if (S.GetLeft().GetValue() % S.GetRight().GetValue() != 0 || S.GetLeft().GetValue() / S.GetRight().GetValue() != S.GetValue())
         {
             return(false);
         }
     }
     return(Halciuho(S.GetLeft()) && Halciuho(S.GetRight()));
 }
 public static int MaxLeafToRoot(BinTreeNode <int> S)
 {
     if (S == null)
     {
         return(0);
     }
     sum += S.GetValue();
     if (sum > MaxSum && S.GetLeft() == null && S.GetRight() == null)
     {
         MaxSum = sum;
     }
     if (MaxLeafToRoot(S.GetLeft()) > MaxLeafToRoot(S.GetRight()))
     {
         return(MaxLeafToRoot(S.GetLeft()));
     }
     else
     {
         return(MaxLeafToRoot(S.GetRight()));
     }
 }
 public static bool CheckNode(int num, BinTreeNode <int> S)
 {
     if (S == null)
     {
         return(false);
     }
     if (S.GetValue() == num)
     {
         return(true);
     }
     return(CheckNode(num, S.GetLeft()) || CheckNode(num, S.GetRight()));
 }
 //public static BinTreeNode<int> Father(BinTreeNode<int> S, int num)
 //{
 //    if (S == null)
 //        return null;
 //    if (S.GetRight() != null)
 //    {
 //        if (S.GetRight().GetValue() == num)
 //            return S;
 //    }
 //    if (S.GetLeft() != null)
 //    {
 //        if (S.GetLeft().GetValue() == num)
 //            return S;
 //    }
 //    return Father(S.GetLeft(), num) +  Father(S.GetRight(), num);
 //}
 public static bool EvenTree(BinTreeNode <int> S)
 {
     if (S == null)
     {
         return(true);
     }
     if (S.GetValue() % 2 != 0)
     {
         return(false);
     }
     return(EvenTree(S.GetLeft()) && EvenTree(S.GetRight()));
 }
 public static void DevideEven(BinTreeNode <int> S)
 {
     if (S != null)
     {
         if (S.GetValue() % 2 == 0)
         {
             S.SetValue(S.GetValue() / 2);
         }
         DevideEven(S.GetLeft());
         DevideEven(S.GetRight());
     }
 }
 public static int Path(BinTreeNode <int> s)
 {
     if (s != null)
     {
         if (s.GetLeft() == null && s.GetRight() == null)
         {
             return(0);
         }
         if (s.GetLeft() != null && s.GetRight() != null)
         {
             return(Math.Max(Path(s.GetRight()), Path(s.GetLeft())) + s.GetValue());
         }
         if (s.GetLeft() != null)
         {
             return(Path(s.GetLeft()) + s.GetValue());
         }
         if (s.GetRight() != null)
         {
             return(Path(s.GetRight()) + s.GetValue());
         }
     }
 }