static Int64 binsearch(int first, Int64 target, int last, Dictionary<Int64> mynumbers)
{
Int32 mid;
int iteration = 0;
while (first < last)
{
iteration = iteration + 1;
mid = (first + last) / 2;
if (mynumbers[mid].Equals(target))
{
return mynumbers[mid];
}
else if (target < mynumbers[mid])
{
last = mid - 1;
}
else if (target > mynumbers[mid])
{
first = mid + 1;
}
}
return 0;
}
我需要字典中的原始位置编号
例如 (2,5,10,3,1,5,6)
0=a[2], 1=a[5], 2=a[10],....
然后搜索 10 给我 2