Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- node TrovaAntenatoComune(node root, node first, node second)
- {
- node antenatoLeft = null;
- node antenatoRight = null;
- if (root.leftC != null)
- {
- if (root.leftC == first || root.leftC == second)
- antenatoLeft = root;
- else
- antenatoLeft = TrovaAntenatoComune(root.leftC, first, second);
- }
- if (root.rightC != null)
- {
- if (root.rightC == first || root.rightC == second)
- antenatoRight = root;
- else
- antenatoRight = TrovaAntenatoComune(root.rightC, first, second);
- }
- if (antenatoLeft == null)
- return antenatoRight;
- if (antenatoRight == null)
- return antenatoLeft;
- return root;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement