Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. import csit.BinNode;
  2. import csit.Node;
  3.  
  4. public class Main {
  5.     public static void main(String[] args) {
  6.        
  7.     }
  8.    
  9.     public static boolean exist(BinNode<Integer> t, int x){
  10.         if(t.getValue() == x){
  11.             return true;
  12.         }else{
  13.             if(t.hasLeft() && t.hasRight()){
  14.                 return exist(t.getLeft(), x) || exist(t.getRight(), x);
  15.             }else if(t.hasLeft()){
  16.                 return exist(t.getLeft(), x);
  17.             }else if(t.hasRight()){
  18.                 return exist(t.getRight(), x);
  19.             }
  20.         }
  21.        
  22.         return false;
  23.     }
  24.    
  25.     public static Node<Integer> check(BinNode<Integer> t1, BinNode<Integer> t2, Node<Integer> list){
  26.         int x = t1.getValue();
  27.        
  28.         if(!exist(t2, x)){
  29.             list.setNext(new Node<Integer>(x, list.getNext()));
  30.         }
  31.        
  32.         list = check(t1.getLeft(), t2, list);
  33.         list = check(t1.getRight(), t2, list);
  34.        
  35.         return list;
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement