Hello,

In my program I work with a number of 3D objects that move around in space. All these objects are labeled with an index i (within an appropriately defined struct Obj[i] ). For any given element i, I have an algorithm that returns an N-dimensional array of ints I[], which tells me the labels of the N nearest neighbors to Obj[i].

Now, given another object label k, I need to do something if Obj[k] *is not* one of the nearest neighbors of Obj[i]. Naively, it would be something like:

Code:
if ( (k != I[0]) && (k != I[1]) && ... && (k != I[N-1]) );
First question: would several "&&" within an "if" statement work as I think they would?

Second issue: Even if the several "&&" work OK, my big problem is that N changes (it is set by the user). Thus, how can I code the above without knowing the value of N ahead of time?. Moreover, because I have a program with runtime graphical output (OpenGL), I need this to be as fast and efficient as possible.

A workaround would be to consider a maximum number of nearest neighbors Nmax and write the "if" statement for this max number. Then, make the first N entries equal to the actual entries of I[N], and the rest, say, a negative int.

However, this feels like the kind of solution someone like me (i.e. with limited knowledge of C) would come up with :-) (and it is certainly not fast...)

Can anyone suggest a proper way to achieve this?

Thanks a lot,

mc61