So, when making an array to search, i always have to sort it first?
Yes. It's impossible to do a binary search on an unsorted list.I could get this binary search to work... no matter what number i enter it will say
"not found" even if its in the array; until, i sorted the array before searching.
Now is a good time to add debugging statements to follow what the code is actually doing.
Before and after every important decision, display the variables that are affected and study the values to see which ones are not as expected.
You're going to have to desk check your program using this technique -- one of the most important debug techniques in your programming arsenal.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944