⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shunxu.cpp

📁 顺序查找是一种简单的查找方法
💻 CPP
字号:
     #include<iostream.h>
     #define N 10
     typedef int keytype ;
     typedef int elemtype ;
     typedef struct
     {    keytype key;                  /* 关键字类型     */
          elemtype other;             /* 其它域  */
     }sqlist;                          /* 顺序表  */
     sqlist R[N+1];
     int seqsearch(sqlist R[],int k)
     {
        int i=N;
        R[0].key=k;
        while(R[i].key!=k)
           i--;
        return i;
     }
     void main()
     {   
	     int x,i;
         cout<<"Creat the sqlist:";
	     for(i=1;i<=N;i++)
         cin>>R[i].key;
         while(1)
	      {
		      cout<<"Input the key you want to search:";
              cin>>x;
     	      int a=seqsearch(R,x);
	          if(a!=0)
			      cout<<"It is the " <<a<<"'th  key!"<<endl;
	          else cout<<"It is not in the sqlist!"<<endl;
	      }
	 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -