码迷,mamicode.com
首页 > 编程语言 > 详细

数组线性查找

时间:2015-03-05 22:20:18      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:

//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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!