逐次検索と半角検索
1097 ワード
#include
using namespace std;
const int max=10;
//
int SeqSearch1(int r[],int n,int k)
{
r[0]=k;// 0 , 1
int i=n;
while(r[i]!=k)
{
i--;
}
return i;//
}
int SeqSearch2(int a[], int n, int x)// a,n ,x
{
int i;
for( i=1;i<=n;i++)
{
if(a[i]==x) // x, x
return i;
}
if(i>n) // , -1
return -1;
}
//
int BinSearch1(int r[],int n,int k)
{
int low=1;
int high=n;
while(low<=high)//
{
int mid=(low+high)/2;
if(r[mid]>k)
{
high=mid-1;
}else if(r[mid]high) return 0;
else
{
if(r[mid]>k) return BinSearch2(r,low,mid-1,k);
else if(r[mid]>a[i];
}
for(int i=1;i<=10;i++)
{
cout<