Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csit.BinNode;
- import csit.Node;
- public class Main {
- public static void main(String[] args) {
- }
- public static boolean exist(BinNode<Integer> t, int x){
- if(t.getValue() == x){
- return true;
- }else{
- if(t.hasLeft() && t.hasRight()){
- return exist(t.getLeft(), x) || exist(t.getRight(), x);
- }else if(t.hasLeft()){
- return exist(t.getLeft(), x);
- }else if(t.hasRight()){
- return exist(t.getRight(), x);
- }
- }
- return false;
- }
- public static Node<Integer> check(BinNode<Integer> t1, BinNode<Integer> t2, Node<Integer> list){
- int x = t1.getValue();
- if(!exist(t2, x)){
- list.setNext(new Node<Integer>(x, list.getNext()));
- }
- list = check(t1.getLeft(), t2, list);
- list = check(t1.getRight(), t2, list);
- return list;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement