This solution looks really complicated, since normalinormaly it should be left<rightleft<=right. In this case you first have to find the left node and then the right one. The simplest solution is just using for loops to get to the coresponding nodes. Also error handling seems to be mising for example when right<left or one or both values are out of bounds.