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 Sum_Values(BinTreeNode <int> S) { if (S == null) { return(0); } return(S.GetValue() + Sum_Values(S.GetLeft()) + Sum_Values(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 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 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()); } } }
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 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())); }