package GeeksforGeeksPractice;

public class _0016PrintAncestorsOfANode {
	public static class TreeNode {
		int val;
		TreeNode left;
		TreeNode right;
		TreeNode(int x) { val = x; }
	}
	public static void main(String args[]){
		TreeNode tn=new TreeNode(50);
		tn.left=new TreeNode(8);
		tn.right=new TreeNode(2);
		tn.left.left=new TreeNode(3);
		//tn.left.right=new TreeNode(5);
		//tn.right.left=new TreeNode(1);
		tn.right.right=new TreeNode(30);
		//getAncestorsOfANode(tn,8,0);
	}
	public static boolean getAncestorsOfANode(TreeNode tn,int val) {
		if(tn!=null)
		{
			return false;
		}
		return true;
	}

}

@@ -27,16 +27,44 @@
 ice;%0D%0A%0D%0A
+import java.util.Arrays;%0D%0A%0D%0A
 public c
@@ -98,16 +98,37 @@
 Node %7B%0D%0A
+%09static int%5B%5D path;%0D%0A
 %09public 
@@ -279,16 +279,39 @@
 gs%5B%5D)%7B%0D%0A
+%09%09path=new int%5B1000%5D;%0D%0A
 %09%09TreeNo
@@ -427,18 +427,16 @@
 (3);%0D%0A%09%09
-//
 tn.left.
@@ -461,18 +461,16 @@
 (5);%0D%0A%09%09
-//
 tn.right
@@ -535,10 +535,8 @@
 %0D%0A%09%09
-//
 getA
@@ -558,10 +558,16 @@
 (tn,
-8,
+path,0,3
 0);%0D
@@ -590,15 +590,12 @@
 tic 
-boolean
+void
  get
@@ -626,16 +626,39 @@
 e tn,int
+%5B%5D path,int pathLen,int
  val) %7B%0D
@@ -686,42 +686,265 @@
 %0A%09%09%09
-return false
+path%5BpathLen%5D=tn.val;%0D%0A%09%09%09pathLen++;%0D%0A%09%09%09if(tn.val==val)%0D%0A%09%09%09%7B%0D%0A%09%09%09%09System.out.println(Arrays.toString(Arrays.copyOf(path, pathLen)))
 ;%0D%0A
+%09
 %09%09%7D%0D%0A%09%09
-return true;
+%09getAncestorsOfANode(tn.left, path, pathLen, val);%0D%0A%09%09%09getAncestorsOfANode(tn.right, path, pathLen, val);%09%09%09%0D%0A%09%09%7D
 %0D%0A%09%7D

Print ancestors of a node completed