0

So i'm having a small issue that seems to arise when getting a negative value back (if the number isn't found in an array.) I'm instructed to essentially take the negative number of where it should be (which would be -7 if it belongs in the 7th index space) and make it a positive index number.

Here is the exact description:

// STEP #2 if the return value is negative then you realize that the number was not 
        // found in the array and this negative number is an encoded index of where the 
        // number belongs.  You must "decode" this index back to the real index it represents. 
        // You do this by doing the opposite operations in the reverse order they were done in 
        // when bsearch "encoded" the index. Once you have a non negative index you can go to 
        // the next step.  
Noivern Evo
  • 111
  • 3
  • 11
  • 2
    What's your question? – user253751 Mar 25 '15 at 21:35
  • By the way, binary searches in general don't return negative indices; this is a feature of *your program*, not a feature of binary search. As such, without seeing your program, it's difficult to know what you're talking about. – user253751 Mar 25 '15 at 21:36
  • That one of the code documentations you do not want to read. "Hey, item not found, but if you search yourself..." – Hannes Mar 25 '15 at 21:38

0 Answers0