Advertisement
Yuvalxp8

BinTree_YuvalPorat

Feb 17th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. public static void InitialScan (BinNode<Integer> t)
  2. {
  3. if (t!=null)
  4. {
  5. System.out.println(t.getValue());
  6. InitialScan(t.getLeft());
  7. InitialScan(t.getRight());
  8. }
  9. }
  10.  
  11. public static void InnerScan(BinNode<Integer> t)
  12. {
  13. if(t!=null)
  14. {
  15. InnerScan(t.getLeft());
  16. System.out.println(t.getValue());
  17. InnerScan(t.getRight());
  18. }
  19. }
  20.  
  21. public static void FinalScan (BinNode<Integer> t)
  22. {
  23. if(t!=null)
  24. {
  25. FinalScan(t.getLeft());
  26. FinalScan(t.getRight());
  27. System.out.println(t.getValue());
  28. }
  29. }
  30.  
  31. public static void printEven(BinNode<Integer> t)
  32. {
  33. if(t!=null)
  34. {
  35. if(t.getValue()%2==0)
  36. System.out.println(t.getValue());
  37.  
  38. printEven(t.getLeft());
  39. printEven(t.getRight());
  40. }
  41. }
  42.  
  43. public static void printIfBiggerThanFather(BinNode<Integer> t)
  44. {
  45. int father = t.getValue();
  46. if(t!=null)
  47. {
  48. if(t.getValue() < father)
  49. System.out.println(t.getValue());
  50.  
  51. printIfBiggerThanFather(t.getLeft());
  52. printIfBiggerThanFather(t.getRight());
  53. }
  54. }
  55.  
  56. public static void printBiggerNodes (BinNode<Integer> t)
  57. {
  58. if(t!=null)
  59. {
  60. if(t.hasLeft() && t.hasRight())
  61. {
  62. if(t.getValue()>t.getLeft().getValue() || t.getValue()>t.getRight().getValue())
  63. System.out.println(t.getValue());
  64. }
  65. printBiggerNodes(t.getRight());
  66. printBiggerNodes(t.getLeft());
  67. }
  68. }
  69.  
  70. public static int Sum (BinNode<Integer> t)
  71. {
  72. int sum = 0;
  73. if(t!=null)
  74. {
  75. sum += t.getValue();
  76. Sum(t.getLeft());
  77. Sum(t.getRight());
  78. }
  79. return sum;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement