public int BinarySearch(int x)
{
//if (Attendees.Length == 0)
// return -1;
int mid = (Count/ 2) -1;
Student cur = new Student(x);
while (cur.CompareTo(Attendees[mid]) != 0)
{
int sCount = Count;
if (cur.CompareTo(Attendees[mid]) < 0)
{
int NCount = sCount / 2;
mid = NCount / 2 - 1;
}
if (cur.CompareTo(Attendees[mid]) > 0)
{
int Start = mid +1;
mid = (Start + sCount) / 2;
}
else
break;
cur = Attendees[mid];
}
if (cur.CompareTo(Attendees[x]) == 0)
return mid;
else
return -1;
}
谁能帮我找出为什么我的二进制搜索不起作用?我对编程很陌生,所以任何帮助都将不胜感激。谢谢你。