标签:
//2015.3.5
//数组线性查找
#include <iostream>
using namespace std;
int linearSearch(const int [],int,int);
int main()
{
const int arraySize = 100;
int dataSet[arraySize];
int searchKey;
int searchReslult;
for(int i=0; i<arraySize; i++)
{
dataSet[i] = i + rand();
}
cin >> searchKey;
searchReslult = linearSearch(dataSet,searchKey,arraySize);
if(searchReslult == 0)
{
cout << "The searchKey in dataSet" <<endl;
}
else
{
cout << "The searchKey out of dataSet" <<endl;
}
return 0;
}
int linearSearch(const int array[],int Key,int sizeOfArray)
{
int reslut;
for(int j=0; j<sizeOfArray; j++)
{
if(array[j] == Key)
{
reslut == 0;
}
else
{
reslut == -1;
}
}
return reslut;
}标签:
原文地址:http://www.cnblogs.com/pucb/p/4316787.html