How to use binary search on arrays??
hi
am creating 2 arrays related each other.all want retrieve datas using binary search..
 string[] country_name ={"america","australia","india","germany" };              foreach (string s in country_name)              {                  console.writeline(s);              }              string[] currency = { "usd","aud","inr","eur"};              foreach (string c in currency)              {                  console.writeline(c);              }  code , in snippet want print currency details of specific country through binary search..can me achieve this...
in order use binary search, first array must sorted, therefore put country names in alphabetical order, , change currency array correspond country names.
if not have write own search procedures, try this:
string some_country = "australia"; int = array.binarysearch(country_name, some_country); if (i < 0) {      console.writeline("country {0} not found.", some_country); } else {      string found_currency = currency[i];      console.writeline("country {0} uses currency: {1}", some_country, found_currency); }  
                                                                          Visual Studio Languages                                                             ,                                                                 .NET Framework                                                     >                                                                 Visual C#                                                                            
 
 
Comments
Post a Comment