Disclaimer: There are some bad practices in this following code

Hello, I just had a few questions on how to correctly format my KD tree K nearest neighbor search. Here is an example of my function.

```
void nearest_neighbor(Node *T, int K) {
  if (T == NULL) return;
  nearest_neighbor(T->left, K); 
  //do stuff find dist etc
  if(?)nearest_neighbor(T->right, K);  
 }

```

This code is confusing so I will try to explain it. My function only takes the k value and a Node T. What I am trying to do is find the distance between the current node and every other value in the structure. These all work, the issue I'm having is understanding when and how to call the recursive calls nearest\_neighbor(T->left/T->right,K) I know I am meant to prune the calls to the right side but I'm not sure how to do this. This is an multidimensional KD Tree by the way. Any guidance to better examples would be very appreciated.