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
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Team Foundation Server Hosting
Become a Sponsor