当前位置:网站首页>DS(LinTabSeqStorStruct)
DS(LinTabSeqStorStruct)
2022-07-20 15:51:00 【itfunc】
#include <bits/stdc++.h>
using namespace std;
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define ERROR 0
#define OK 1
#define OVERLOW -2
typedef struct {
int *elem;
int length;
int listsize;
} sqlist;
int InitList_Sq(sqlist &L) {
L.elem = (int *)malloc(sizeof(int) * LIST_INIT_SIZE);
if (!L.elem) exit(OVERFLOW);
L.length = 0;
L.listsize = LIST_INIT_SIZE;
return OK;
}
int listinsert(sqlist &L, int i, int e) {
int *newbase, *p, *q;
if (i < 1 || i > L.length + 1) return ERROR;
if (L.length >= L.listsize) {
newbase =
(int *)realloc(L.elem, (L.listsize + LISTINCREMENT) * sizeof(int));
if (!newbase) return OVERFLOW;
L.elem = newbase;
L.listsize += LISTINCREMENT;
}
q = L.elem + i - 1;
for (p = L.elem + L.length - 1; p >= q; --p) *(p + 1) = *p;
*q = e;
++L.length;
return OK;
}
int locate(sqlist L, int e) {
int i, *p;
i = 1;
p = L.elem;
while (i <= L.length && e != *p) {
++i;
++p;
}
if (i <= L.length)
return i;
else
return 0;
}
void unionmerge(sqlist &la, sqlist lb) {
int i, e;
for (i = 0; i < lb.length; ++i) {
e = *(lb.elem + i);
if (!locate(la, e)) listinsert(la, la.length + 1, e);
}
}
int ListDelete_Sq(sqlist &L, int i, int &e) {
int *p, *q;
if (i < 1 || i > L.length) return ERROR;
p = &(L.elem[i - 1]);
e = *p;
q = L.elem + L.length - 1;
for (++p; p <= q; ++p) *(p - 1) = *p;
--L.length;
return OK;
}
int main() {
int i, m, n, e;
sqlist la, lb;
cout << " Please enter the first set la The number of elements in :";
cin >> m;
cout << " Please enter the second set lb The number of elements in :";
cin >> n;
InitList_Sq(la);
cout << " Please enter the second set la The number of elements in :";
for (i = 1; i <= m; ++i) {
cin >> e;
listinsert(la, i, e);
}
cout << " The first set la Medium " << la.length << " The elements are :";
for (i = 0; i < la.length; i++) cout << *(la.elem + i) << " ";
cout << endl;
InitList_Sq(lb);
cout << " Please enter the second set lb Elements in :";
for (i = 1; i <= n; ++i) {
cin >> e;
listinsert(lb, i, e);
}
cout << " The second set lb Medium " << lb.length << " The elements are :";
for (i = 0; i < lb.length; i++) cout << *(lb.elem + i) << " ";
cout << endl;
unionmerge(la, lb);
cout << endl;
cout << " Merged set la Medium " << la.length << " The elements are :";
for (i = 0; i < la.length; i++) cout << *(la.elem + i) << " ";
cout << endl;
cout << " Please enter the number of elements to delete :";
cin >> i;
if (ListDelete_Sq(la, i, e)) cout << " The deleted element is :" << e << endl;
cout << " Set after deletion la Medium " << la.length << " The element is :";
for (i = 0; i < la.length; i++) cout << *(la.elem + i) << " ";
cout << endl;
return 0;
}
边栏推荐
- mongodb-探索阶段[通俗易懂]
- 【深度】新派LaaS协议Elephant:重振DeFi赛道发展的关键
- 实验二 货物进销管理系统
- How does markdown draw a sequence diagram? One is enough
- 【WSN通信】基于matlab生物地理学优化HWSN节能聚类协议【含Matlab源码 1989期】
- vim中单词操作方法总结
- Use octree structure to manage scenes
- 【服务器数据恢复】某品牌ProLiant服务器raid瘫痪,数据库文件丢失,数据库文件备份损坏的数据恢复案例
- New solutions to go points (II) map solution
- Pytorch, used by the nonzero instance
猜你喜欢
Troubleshooting ideas that can solve 80% of faults
15. 简单工资管理系统设计
才22岁!这位'00后'博士拟任职985高校!
数据中台、商业智能BI业务访谈(一):行业和业务研究的准备
uniapp通过addInterceptor拦截路由跳转,控制页面是否需要登录
Spark高效数据分析03、Spack SQL
Assignment of golang interface variables and call of methods
[matlab project practice] Research on UAV image compression technology based on region of interest
Image annotation open source gadget labelimg
golang 接口变量的赋值和方法的调用
随机推荐
[depth] the new LAAS agreement elephant: the key to revitalizing the development of the defi track
constructor
mysql 往表中某个字段的字符串后追加字符串[通俗易懂]
运营商的时代之旅:种下5.5G的魔豆,攀上数字化的天空花园
自动机器学习库:TPOT の 学习笔记
Troubleshooting ideas that can solve 80% of faults
15. 简单工资管理系统设计
pytorch,初始化tensor
Ceres计算Bundle Adjustment
【LSTM回归预测】基于matlab attention机制LSTM时间序列回归预测【含Matlab源码 1992期】
clickhouse 20. Integration of X and Prometheus + grafana (III)
Research on the best implementation scheme of feign
C语言深度剖析笔记1
CUDA error in nchwtonchhw2 solution
PG Database install Timescale Database and Backup configuration
Iterm2安装与使用
ES6 -- iterator, basic use of generator
[ERROR] COLLATION ‘utf8_unicode_ci‘ is not valid for CHARACTER SET ‘latin1‘
Wechat applet (login, sharing, payment)
参与开源社区还有证书拿?