Print all nodes at a distance k from a given node

https://ide.codingblocks.com/s/91563 I am getting wrong answer for this code. Kindly tell me the error int this code. thank you!

Your code is compiling successfully, but not producing any output, plz use int target, instead of taking target to be a node, and then try to submit your code

https://ide.codingblocks.com/s/94494 my code is giving correct answer for 1 testcase. please tell me the error. thank you.

Use a vector to store the nodes, for every test cases, whenever your value gets equal to target node. For eg : if(dl!=-1)
{
if(dl+1==k)
v.push_back(root->data);
else
print_k_distance_down(root->right,k-dl-2);
return 1+dl;
}
Do like this,

if we using vector to store output do i have to sort it??
and when will it be cout? in main or at the end of program?

Yes, you have to sort the vector
and also you can have cout at the end after sorting the output.