SIGN UP MEMBER LOGIN:    
ARTICLE

Binary Search Using ArrayList

Posted by Mahesh Chand Articles | ASP.NET & Web Forms January 10, 2000
The ArrayList class provide binary search algorithm and more...
Reader Level:

Tools Used Visual C# .NET
Assembly mscorlib.dll
Namespace System.Collections

Recently, I need to use binary search in my applications and I found ArrayList class very handy to do so. 
The ArrayList class Implements a collection of objects using an array whose size is dynamically increased as required. The ArrayList class is very useful if you are playing with arrays and need to add, remove, indexed, or search data in a collection.
Adding data to an ArrayList
Adding data to an ArrayList is pretty easy. Just call Add member of the class:

ArrayList dataArray =
new ArrayList();
for ( int i = 0; i<20; i++ )
{
dataArray.Add( i );
}

or:
dataArray.Add( "Object type" );

The Add member takes an argument of Object type. You can add any value to the array.

Delete data from an ArrayList

The Remove and RemoveAt members are used to delete data from an ArrayList
// Remove the element containing "3".
myAL.Remove( "3" );

Searching elements in ArrayList

The BinarySearch member of the ArrayList was very useful for me. This member returns the zero-based index of a specific element in the sorted ArrayList or a portion of it, using a binary search algorithm.
int myIndex=myList.BinarySearch( 3 );
That's it..  The ArrayList class is much more fun than this. See documentation for more details.

share this article :
post comment
 

hello sir; can u tell me how we can do simulation of bst using graph. regards sumaira manzoor

Posted by sumaira manzoor hussain khan Mar 17, 2012
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Become a Sponsor