Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void q1 (BinNode<Integer> bt)
- {
- if(bt == null)
- return;
- if(bt.getValue()%2==0)
- bt.setValue(bt.getValue()/2);
- q1(bt.getLeft());
- q1(bt.getRight());
- }
- public static void q2 (BinNode<Integer>bt)
- {
- if(bt == null)
- return;
- if( (!(bt.hasLeft())) && bt.hasRight())
- bt.setLeft(new BinNode<Integer>(0));
- if( (!(bt.hasRight())) && bt.hasLeft())
- bt.setRight(new BinNode<Integer>(0));
- q2(bt.getLeft());
- q2(bt.getRight());
- }
- public static int q3 (BinNode<Integer>bt)
- {
- if(bt == null)
- return 0;
- if(bt.getValue()%2==0)
- return 1 + q3(bt.getLeft()) + q3(bt.getRight());
- return q3(bt.getLeft()) + q3(bt.getRight());
- }
- public static int q4 (BinNode<Integer>bt)
- {
- if(bt == null)
- return 0;
- if(bt.hasRight())
- return bt.getRight().getValue() + q4(bt.getLeft()) + q4(bt.getRight());
- return q4(bt.getLeft());
- }
- public static boolean q5 (BinNode<Character>bt,char x)
- {
- if(bt == null)
- return false;
- if(bt.getValue() == x)
- return true;
- return q5(bt.getLeft(),x) || q5(bt.getRight(),x);
- }
- public static boolean q6 (BinNode<Integer>bt)
- {
- if(bt == null)
- return true;
- if(bt.getValue()%2!=0)
- return false;
- return q6(bt.getLeft()) && q6(bt.getRight());
- }
- public static int q7(BinNode<Integer>bt)
- {
- if(bt==null)
- return 0;
- return bt.getValue() + Math.max(q7(bt.getLeft()),q7(bt.getRight()));
- }
- public static boolean ezer(BinNode<Integer>bt,int sum,int treesum)
- {
- if(bt==null)
- return false;
- treesum += bt.getValue();
- if( treesum == sum && (!(bt.hasLeft())) && (!(bt.hasRight())) )
- return true;
- return ezer(bt.getLeft(),sum,treesum) || ezer(bt.getRight(),sum,treesum);
- }
- public static boolean rootsum(BinNode<Integer>bt,int sum)
- {
- return ezer(bt,sum,0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement