Re: Confusing Arraylist BinarySearch problem

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



SAPArray.Sort()

Perfect! Thanks a bunch! I never knew that. I guess I've just been lucky
this whole time or something else was always sorting my data prior to
creation.

Am I to assume that once it hit where it thinks the value should be it stops
looking? If so then that's probably a huge speed increase in large array
scenarios.

Thanks again!


Thanks, Justin Emlay SAP Basis Administrator / Systems Department Maisto
International, Inc. 909-357-7988 ext.360 909-357-9958 fax JEmlay@xxxxxxxxxx
www.maisto.com
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@xxxxxx> wrote in message
news:OeuPchKGHHA.2128@xxxxxxxxxxxxxxxxxxxxxxx
"Justin" <Justin@xxxxxxxxxx> schrieb:
We can even shorten up the issue. Let's say this is my array:

SAPArray.Add("04876497")
SAPArray.Add("48764205")
SAPArray.Add("48764212")
SAPArray.Add("48764229")
SAPArray.Add("48764236")
SAPArray.Add("48764243")
SAPArray.Add("48764250")
SAPArray.Add("48764267")
SAPArray.Add("48764274")
SAPArray.Add("48764281")
SAPArray.Add("48764298")
SAPArray.Add("48764304")
SAPArray.Add("48764311")
SAPArray.Add("48764328")
SAPArray.Add("48764335")
SAPArray.Add("48764342")
SAPArray.Add("48764359")
SAPArray.Add("48764366")
SAPArray.Add("48764373")
SAPArray.Add("48764380")
SAPArray.Add("48764397")
SAPArray.Add("11111111")
SAPArray.Add("22222222")
SAPArray.Add("33333333")
SAPArray.Add("44444444")
SAPArray.Add("55555555")
SAPArray.Add("66666666")
SAPArray.Add("77777777")

When I run this code directly after the array creation:
Dim index2 As Integer = SAPArray.BinarySearch("48764373", New
CaseInsensitiveComparer())
MsgBox(index2)

I get a negative value even though that item exists.

Items must be sorted in order to search an item using binary search. You
can call the arraylist's 'Sort' method to sort it.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


.



Relevant Pages

  • Re: Confusing Arraylist BinarySearch problem
    ... When I run this code directly after the array creation: ... Dim index2 As Integer = SAPArray.BinarySearch ... Items must be sorted in order to search an item using binary search. ... You can call the arraylist's 'Sort' method to sort it. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: A faster way of finding historical highs/lows
    ... >>using sort(), then a binary search. ... By binary search, ... If you have this in a relational database, ... database can answer the question quicker for you, ...
    (comp.lang.python)
  • Re: Binary Search
    ... your stated needs are to sort the list and to find duplicates. ... I sort the array before searching (as is required with binary search). ... We're in the non-match zone. ...
    (comp.lang.pascal.delphi.misc)
  • Re: A faster way of finding historical highs/lows
    ... some preprocessing will likely make things ... > using sort(), then a binary search. ... By binary search, ...
    (comp.lang.python)
  • Re: Efficient Java Programming
    ... If you're using a binary search on a large data set and adding missing ... faster than using a sort. ... martin@ | Martin Gregorie ...
    (comp.lang.java.programmer)