Connecting Tech Pros Worldwide Forums | Help | Site Map

ArrayList Insert and BinarySearch

Zanzibar
Guest
 
Posts: n/a
#1: Nov 16 '05
H

In Delphi the Search method has Two return values. 1 Bool to indicate if it is found and 1 integer to return the possition
If the bool was false, the index was the possition where the item should come. This was easy to call insert

Is their a way I can do the same in arraylist? I have an arraylist that rarely changes, but I need the very fast indexing and iterating. I don't mind an insert being a little slower

BTW, is their a way I could access these newsgroups with Outlook express? This web interface is not very "me"

Kind regards

Alexander

Sherif ElMetainy
Guest
 
Posts: n/a
#2: Nov 16 '05

re: ArrayList Insert and BinarySearch


Hello

The BinarySearch method does what you want. See MSDN docs.

Yes you can access these newsgroups with Outlook Express. Add a news account
with news server msnews.microsoft.com

Best regards,
Sherif

"Zanzibar" <anonymous@discussions.microsoft.com> wrote in message
news:78F94D6F-6D6A-478B-AA5E-6DDA59964FD9@microsoft.com...[color=blue]
> Hi
>
> In Delphi the Search method has Two return values. 1 Bool to indicate if[/color]
it is found and 1 integer to return the possition.[color=blue]
> If the bool was false, the index was the possition where the item should[/color]
come. This was easy to call insert.[color=blue]
>
> Is their a way I can do the same in arraylist? I have an arraylist that[/color]
rarely changes, but I need the very fast indexing and iterating. I don't
mind an insert being a little slower.[color=blue]
>
> BTW, is their a way I could access these newsgroups with Outlook express?[/color]
This web interface is not very "me".[color=blue]
>
> Kind regards
>
> Alexander[/color]


Alexander Muylaert
Guest
 
Posts: n/a
#3: Nov 16 '05

re: ArrayList Insert and BinarySearch


Hi

thanks for the tip on outlook.

Aha :-)

Console.WriteLine( "The object to search for ({0}) is not found. The next
larger object is at index {1}.", myObject, ~myIndex );

Has the ~ something to do with it?

Very hard to know if doesn't mention this somewhere.

Kind regards

Alexander


Jon Skeet [C# MVP]
Guest
 
Posts: n/a
#4: Nov 16 '05

re: ArrayList Insert and BinarySearch


Sherif ElMetainy <elmeteny.NOSPAM@wayout.net.NOSPAM> wrote:[color=blue]
> The BinarySearch method does what you want. See MSDN docs.[/color]

BinarySearch will only work if the ArrayList is sorted. IndexOf will
always work.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Mattias Sjögren
Guest
 
Posts: n/a
#5: Nov 16 '05

re: ArrayList Insert and BinarySearch


[color=blue]
> Console.WriteLine( "The object to search for ({0}) is not found. The next
>larger object is at index {1}.", myObject, ~myIndex );
>
> Has the ~ something to do with it?[/color]

The BinarySearch method is documented to return "a negative number,
which is the bitwise complement of the index of the next element that
is larger than value or, if there is no larger element, the bitwise
complement of Count" if the value isn't found.

~ is C#'s binary complement operator.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Closed Thread