Advertisement
Guest User

TrovaAntenatoComune

a guest
Feb 9th, 2012
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. node TrovaAntenatoComune(node root, node first, node second)
  2.     {
  3.       node antenatoLeft = null;
  4.       node antenatoRight = null;
  5.  
  6.       if (root.leftC != null)
  7.       {
  8.         if (root.leftC == first || root.leftC == second)
  9.           antenatoLeft = root;
  10.         else
  11.           antenatoLeft = TrovaAntenatoComune(root.leftC, first, second);
  12.       }
  13.  
  14.       if (root.rightC != null)
  15.       {
  16.         if (root.rightC == first || root.rightC == second)
  17.           antenatoRight = root;
  18.         else
  19.           antenatoRight = TrovaAntenatoComune(root.rightC, first, second);
  20.       }
  21.  
  22.       if (antenatoLeft == null)
  23.         return antenatoRight;
  24.  
  25.       if (antenatoRight == null)
  26.         return antenatoLeft;
  27.  
  28.       return root;
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement