【发布时间】:2011-07-08 10:14:33
【问题描述】:
你能帮我用这个简单的C++代码吗,我不知道这里有什么问题?
#include <iostream>
#include <string>
using namespace::std;
template <class Type>
Type binsearch (Type item,Type *table,Type n)
{
int bot=0;
int top=n-1;
int mid, cmp;
while (bot<= top)
{
mid=(bot+top)/2;
if(item==table(mid))
return (mid);
else if (item <table[mid])
top=mid-1;
else
bot=mid+1;
}
return -1;
}
int main ()
{
int nums[]={10, 12, 30, 38, 52, 100};
cout<< binsearch(52, nums, 6);
}
【问题讨论】:
-
至少发布错误是什么以及它出现在哪里
-
@NAIEM:我建议您开始学习如何处理错误消息中的信息。编译器可能会告诉您问题出在哪一行,这应该限制了搜索。如果您仍然无法理解该行中发生的情况,请发布问题,但不要忘记提供编译器为您提供的完整信息(即行号)(在报告错误的行中添加注释:@ 987654322@之类的)
标签: c++