线性表的线性表示;初始化,输出,插入,删除,查找;

news/2025/2/6 4:35:00/
#include <iostream>
#include <algorithm>//fill()
#define InitSize 5using namespace std;/*线性表:线性表示;初始化,输出,插入,删除,查找*///静态分配数组
typedef struct{int data[InitSize];int length_;
}Sqlist_;//动态分配数组
typedef struct{int *data;int MaxSize,length;
}SqList;void OutputList(SqList L){for(int i=0;i<L.MaxSize;i++)printf("%d ",L.data[i]);printf("\n");
}void InitList(SqList &L){L.MaxSize=InitSize;L.length=L.MaxSize-1;//L.data=(int *)malloc(sizeof(int)*L.MaxSize);L.data=new int[L.MaxSize];fill(L.data,L.data+L.MaxSize,-1);for(int i=0;i<L.length;i++)L.data[i]=i;
}//插入
bool ListInsert(SqList &L,int i,int e){for(int j=L.length;j>=i;j--){L.data[j]=L.data[j-1];}L.data[i]=e;L.length++;return true;
}//删除
bool ListDelete(SqList &L,int i){for(int j=i;j<L.length-1;j++)L.data[j]=L.data[j+1];L.length--;fill(L.data+L.length,L.data+L.MaxSize,-1);
}//查找
int LocateElem(SqList L,int e){for(int i=0;i<L.length;i++)if(L.data[i]==e)return i;return -1;
}int main()
{/*线性表:线性表示;初始化,输出,插入,删除,查找*/SqList L;InitList(L);OutputList(L);ListInsert(L,1,9);OutputList(L);ListDelete(L,1);OutputList(L);LocateElem(L,1);printf("%d",LocateElem(L,1));return 0;
}

http://www.ppmy.cn/news/1140012.html

相关文章

关于 Vue-iClient-MapboxGL 的使用注意事项

官网&#xff1a;https://iclient.supermap.io/web/apis/vue/zh/api/guide/installation.html 关于图的使用&#xff0c;其余的引入步骤不再赘述&#xff0c;仅说注意事项。 推荐使用的是全局引入&#xff0c;也就是完整引入 因为单独引入我踩了不少坑&#xff0c;比如说 cs…

运行huggingface Kosmos2报错 nameerror: name ‘kosmos2tokenizer‘ is not defined

尝试运行huggingface上的Kosmos,https://huggingface.co/ydshieh/kosmos-2-patch14-224失败,报错: nameerror: name kosmos2tokenizer is not defined查看报错代码: vi /root/.cache/huggingface/modules/transformers_modules/ydshieh/kosmos-2-patch14-224/48e3edebaeb…

KylinOSv10系统k8s集群启动mysql5.7占用内存高的问题

问题现象 麒麟系统搭建k8s集群 mysql的pod启动失败 describe查看ommkill&#xff0c;放大limit资源限制到30G依旧启动失败 系统 报错信息 原因 内存占用太高 open_files_limit初始化太高 解决&#xff1a; 1、更换镜像 链接: https://pan.baidu.com/s/1b9uJLcc5Os0uDqD1e…

第1次 更多的bash shell命令

1.检测程序 程序都是进程在运行&#xff0c;进程里面有很多线程&#xff0c;面试经常会问进程和线程的区别&#xff0c;线程可以访问另一个线程的什么什么的&#xff0c;这些我都听腻了&#xff0c;区别就是进程会分配程序需要的空间&#xff0c;创建线程需要的资源&#xff0c…

vue启动项目,npm run dev出现error:0308010C:digital envelope routines::unsupported

运行vue项目&#xff0c;npm run dev的时候出现不支持错误error:0308010C:digital envelope routines::unsupported。 在网上找了很多&#xff0c;大部分都是因为版本问题&#xff0c;修改环境之类的&#xff0c;原因是对的但是大多还是没能解决。经过摸索终于解决了。 方法如…

【c++】解决使用 std::map 时报错 no match for ‘operator<’

文章目录 1. 发现问题2. GPT 分析问题3. 解决问题 1. 发现问题 c 代码中使用复杂类型 std::map<Eigen::Vector2i, std::set<long unsigned int>> 时报错 no match for ‘operator<’ (operand types are ‘const Eigen::Matrix<int, 2, 1>’ and ‘const…

AIGC AI绘画 Midjourney 参数大全详细列表

AIGC ChatGPT 职场案例60集&#xff0c; Power BI 商业智能 68集&#xff0c; 数据库Mysql8.0 54集 数据库Oracle21C 142集&#xff0c; Office&#xff0c; Python &#xff0c;ETL Excel 2021 实操&#xff0c;函数&#xff0c;图表&#xff0c;大屏可视化 案例实战 http:…

k8s 集群安装(vagrant + virtualbox + CentOS8)

主机环境&#xff1a;windows 11 k8s版本&#xff1a;v1.25 dashboard版本&#xff1a;v2.7.0 calico版本&#xff1a; v3.26.1 CentOS8版本&#xff1a;4.18.0-348.7.1.el8_5.x86_64 用到的脚本&#xff1a; https://gitcode.net/sundongsdu/k8s_cluster 1. Vagrant创建…