zoukankan      html  css  js  c++  java
  • 检索之顺序检索

    上代码:

    #include<iostream>
    #include<vector>
    using namespace std;
    
    class Item
    {
    private:
        int Key;
    public:
        Item(){}
        Item(int value):Key(value){}
        int getKey()
        {
            return Key;
        }
        void setKey(const int &K)
        {
            Key = K;
        
        }
    };
    
    int SeqSearch(vector<Item *> &dataList, int length, const int &K)
    {
        int i = length;
        dataList[0]->setKey(K);
        while(dataList[i]->getKey() != K)
            i--;
        return i;
    }
    
    int main()
    {
        vector<Item *> datalist(10);
        cout<<"输入Key值:" << endl;
        int key = 0;
        int i=0;
        int ifn;
        while(key >= 0)
        {
            cin>>key;
            datalist[i]=new Item(key);
            i++;
        }
        cout<<"input the Key to be found :" << endl;
        cin>> ifn;
        int fn=SeqSearch(datalist,i-1,ifn);
        if(fn>0)
            cout<<"Find the key int the position :" << fn << endl;
        else
            cout<<"can't find the Key" <<endl;
        return 0;
    }

    程序运行结果:

    Fight fight fight ! 你有你的奇迹 ! Fight fight fight ! Just to be yourself !
  • 相关阅读:
    Windows下安装redis
    flask-redirect
    MySQLHelper
    配置信息
    注释习惯
    SQL2012 附加数据库提示5120错误解决方法
    Union-SQL Server学习笔记
    存储过程
    模糊查询&&日期时间操作
    数据库表的设计
  • 原文地址:https://www.cnblogs.com/sjlove/p/3105135.html
Copyright © 2011-2022 走看看