数据结构-查找-顺序查找(1)时间复杂度(n+1)/2
来源:互联网 发布:彩蝶排课软件 编辑:程序博客网 时间:2024/06/05 03:02
1.代码区
#include <iostream>
#define MAX 111
using namespace std;
typedef struct{
int key;//关键字
//other data
} ElemType;
typedef struct{
ElemType *R;//如上
int length;//顺序表长度
} Sstable;
int searchSeq(Sstable st, int key);
int main(){
//定义一个顺序表并开辟一个足够的数组空间
Sstable st;
st.R = new ElemType[MAX];
//输入一段无序的序列
cout << "please input sequence length:\n";
cin >> st.length;
cout << "please input sequence elemts:\n";
for(int i = 0; i < st.length; i++){
cin >> st.R[i].key;
}
//调用查找函数
int key;
cout << "please input the number you want to find:\n";
cin >> key;
int index = searchSeq(st,key);
//输出查找结果
if(index != 0){
cout << "The number of number subscript to be found is:";
cout << index << endl;
}
else{
cout << "No answer!" << endl;
}
return 0;
}
int searchSeq(Sstable st, int key){
int i;
st.R[0].key = key;
for(i = st.length; st.R[i].key != key; i--);
return i;
}
2.结果区
- 数据结构-查找-顺序查找(1)时间复杂度(n+1)/2
- 数据结构-查找-二分查找(1)有序表复杂度(lg(n))
- 时间复杂度为o(N)查找1至N-1构成的a[N]重复元素
- 时间复杂度为o(N)查找1至N-1构成的a[N]重复元素
- 时间复杂度为o(N)查找1至N-1构成的a[N]重复元素
- 【数据结构】查找-顺序查找
- 数据结构基础(2) --顺序查找 & 二分查找
- 数据结构基础(2) --顺序查找 & 二分查找
- 数据结构基础(2) --顺序查找 & 二分查找
- 数据结构基础(2) --顺序查找 & 二分查找
- 在O(n)时间复杂度内查找前三名算法
- 折半查找的时间复杂度log2(n)的推导
- 查找(1)---顺序查找
- 数据结构中排序和查找各种时间复杂度
- 数据结构中排序和查找各种时间复杂度
- 【自考】——数据结构☞时间复杂度&平均查找长度
- 常见数据结构的查找、插入、删除时间复杂度
- 数据结构--顺序查找、二分查找
- JUC教程
- nginx FastCGI错误Primary script unknown解决办法(访问php提示"File not found.)
- C# 通过exchange发送邮件 defaultuser and use username_password
- 十张思维导图掌握javascript重点
- fresco加载图片+retrofit网络请求+rxjava2+xrecyclerview下拉刷新上拉加载
- 数据结构-查找-顺序查找(1)时间复杂度(n+1)/2
- VS2015 C# System.Data.SQLite
- Android 之路12---Java基础7
- 【iOS】自定义CALayer可能会出现没有动画过程但有动画结果的解析
- CUDA
- 改变viewPager滑动的速度,利用反射完美实现
- layui获取选中行数据
- 递归算法及经典例子实现
- HTML select 复选框 互相值转换