【发布时间】:2013-02-02 13:31:41
【问题描述】:
我有一个排序数组 double。 目标是在数组中查找索引。 其中包含
例如,数组包含索引范围为 [0 .. 4] 的数字 {0, 5, 12, 34, 100}。
搜索值=25。我想得到 index=2(出现范围在 12 到 34 之间)
我不明白在这种情况下如何运行二进制搜索。
public class MyComparer : IComparer<double>
{
public int Compare(double x, double y)
{
//<-------- ???
}
}
public double[] spline_x;
MyComparer cmpc = new MyComparer();
int i=Array.BinarySearch(spline_x, x, cmpc);
【问题讨论】:
标签: c# arrays algorithm find binary-search