What's Here?
- Members: 137,214
- Replies: 481,423
- Topics: 75,054
- Snippets: 2,567
- Tutorials: 675
- Total Online: 2,269
- Members: 111
- Guests: 2,158
|
Traverses the list to find data
|
Submitted By: KYA
|
|
|
Rating:
|
|
Views: 536 |
Language: C++
|
|
Last Modified: July 18, 2008 |
|
Instructions: Use within a program to search data for specific values--list must already be sorted! |
Snippet
int BinarySearch(int A[], int value, int low, int high)
{
while (low <= high)
{
mid = (low + high) / 2;
if (A[mid] > value)
high = mid - 1;
else if (A[mid] < value)
low = mid + 1;
else
return mid; // found
}
return -1; // not found
}//end binary search
Copy & Paste
|
|
|
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|