二分查找
適用于有序表查找, 包括二叉排序樹(shù)
int BinarySearch(int *array, int aSize, int key)
{
if ( array == NULL || aSize == 0 )
return -1;
int low = 0;
int high = aSize - 1;
int mid = 0;
while ( low <= high )
{
mid = (low + high )/2;
if ( array[mid] < key)
low = mid + 1;
else if ( array[mid] > key )
high = mid - 1;
else
return mid;
}
return -1;
}
散列查找
請(qǐng)看本博客數(shù)據(jù)結(jié)構(gòu)與算法hash表文章
http://www.reibang.com/writer#/notebooks/15612823/notes/16627768