By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,481 Members | 979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,481 IT Pros & Developers. It's quick & easy.

How to use ArrayList.BinarySearch if the object is not found.

P: n/a
I have a list of strings and I would like to insert them in order as they
come up.

I am trying to use ArrayList.BinarySearch which (theoretically) returns the
negative bitwise compliment. And I should be able to find the index of the
element one higher than where I should insert.

How?

I'm not getting it.

I created an arraylist with strings "1", "3", "5" and when I did a
BinarySearch for "2" I get (-100001). The bitwise compliment of which is
(100000), not (1) like I should expect.

And a BinarySearch for "4" returns (-200002).

I've got no idea what this is doing. How do you use this function?

Thanks in advance,
Tom Padilla
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

When I run the following code:

Dim al As New ArrayList

al.Add("1")
al.Add("3")
al.Add("5")

MsgBox((Not al.BinarySearch("4")).ToString)
I get 2 in the MsgBox. Are the items in your ArrayList sorted? They
must be sorted for the BinarySearch method to work.

Nov 21 '05 #2

P: n/a
"Chris Dunaway" <du******@gmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...

When I run the following code:

Dim al As New ArrayList

al.Add("1")
al.Add("3")
al.Add("5")

MsgBox((Not al.BinarySearch("4")).ToString)
I get 2 in the MsgBox. Are the items in your ArrayList sorted? They
must be sorted for the BinarySearch method to work.


That was it.

Just "NOT".

Thanks man. I was using XOR, XOR -1, -1 + XOR, NOR, NOR x -1... all kinds
of crap.

Thanks,
Tom P.
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.