Created
April 21, 2018 08:26
-
-
Save Kishy-nivas/f52baa7a4738e388af41d00d027dfbc3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class GfG | |
| { | |
| public HashSet<Integer> set = new HashSet<Integer>(); | |
| public void printCommon(Node root1,Node root2){ | |
| inOrder(root1); | |
| print(root2); | |
| //System.out.println(); | |
| } | |
| public void inOrder(Node root){ | |
| if(root == null) | |
| return; | |
| inOrder(root.left); | |
| set.add(root.data); | |
| inOrder(root.right); | |
| } | |
| public void print(Node root){ | |
| if(root == null){ | |
| return; | |
| } | |
| print(root.left); | |
| if(set.contains(root.data)){ | |
| System.out.print(root.data + " "); | |
| } | |
| print(root.right); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment