#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
typedef int KeyType;
typedef struct ElemType
{
KeyType key;
}ElemType;
int SeqSearch(ElemType A[],int n,KeyType key)
{
for(int i =0;i<n;i++)
{
if(A[i].key == key)
break;
}
if(i<n)
return i;//查找成功
else
return -1;//查找失败
}
int main()
{
ElemType A[10] = {0,1,2,3,4,5,6,7,8,9};
cout <<SeqSearch(A,10,4)<<endl;
return 0;
}
最简单的顺序查找
最新推荐文章于 2022-08-04 17:25:45 发布