I need help with BinarySearch.....

bdeitsch
01-25-2004, 06:24 AM
I have a programming exercise for a VB.net class that I am taking. I have to read 200 flight numbers from a .txt file into an array. Then I have to ask the user for a flight number and then do a BinarySearch to see if the number is in the array, making it a valid flight. If it is not in the array, it is then an invalid flight.

I read the 200 numbers into the array just fine. I can place a listbox on my form and instruct it to display all array values and it spits out the numbers from the .txt file. So I know the flight numbers made it to the array just fine.

My problem is in doing a BinarySearch for the flight number. It's not working right and I don't know where the problem is. Every number that I input comes back as invalid, even though I know the number is in the array.

I can do an If-Then statement to run thru the entire array and test each number against the one the user entered, but the directions specifically say to use BinarySearch. My textbook talks about it, but doesn't explain how to use it properly.

Any help provided would be very much appreciated.

Thank you.

Bill Deitsch

Optikal
01-25-2004, 11:44 AM
Binary Search explanation here: http://www.tbray.org/ongoing/When/200x/2003/03/22/Binary

OnErr0r
01-25-2004, 06:24 PM
You might want to look at ArrayList.BinarySearch() too. :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum