你有学过数据结构没有?
你看一下,看了有哪不懂的可以问我!
我再帮你解答,你这一下让我写程序,我没时间写啊!
//我暂时就给你写了二分查找的,其它的过两天给你,我没时间写啊,一直都有课
#include
using namespace std;
const int size =5;
//*****
bool find(int num[],int first,int length,int value)
{
if(first < length || length > 0){
if(value == num[(first+length)/2]) return true;
else if( value < num[(first+length)/2]) {find(num,first,(first+length)/2 - 1, value);}
else {find(num,(first+length)/2+1,length, value);}
}
else{
return false;
}
}
//****
int _tmain(int argc, _TCHAR* argv[])
{
int num[size],first=0,length=size,i,value;
cout<<"Input the num : \n";
for(i=0;i
cout<<"The searched number: ";
cin>>value;
if( !find(num,first,length,value) )
cout<<"No found;\n";
else
cout<<"Yes found the number\n";
return 0;
}
// 散列表的!
#include
using namespace std;
int HashSearch1(int ht[ ], int m, int k)
{
int j=k%m;
if (ht[j]==k)
return j; //没有发生冲突,比较一次查找成功
int i=(j+1) % m;
while (i!=j)
{
if (ht[i]==k)
return i; //发生冲突,比较若干次查找成功
i=(i+1) % m; //向后探测一个位置
}
if (i==j)
throw "溢出";
else
ht[i]=k; //查找不成功时插入
}
void main()
{
int s[11]={11,0,0,47,0,0,0,7,29,8,0};
cout<<"散列表中的元素有:\n";
for(int i=0;i<11;i++)
{
cout< }
cout<<"\n"<<"执行查找操作,结果为:\n"; //查找操作
cout<
}
我想顺序查找不用我写了吧,你那同学学数据结构的顺序查找都不会吗?