当前位置:网站首页>¥ 1-2 example 2.2 put the union of two sets into the linear table
¥ 1-2 example 2.2 put the union of two sets into the linear table
2022-07-25 09:54:00 【Ye Xiaobai】
Put the union of two sets into a linear table
Title Description

The sample input
2
1 3
3
5 3 7
Sample output
1 3 5 7
Source code
#include<iostream>
#include<malloc.h>
using namespace std;
typedef int ElemType;
const int MaxSize = 1000; // Define maximum storage
class SqList
{
public:
int data[MaxSize]; // Array of structs
int length; // length
};
void InitList(SqList*& L) // Initialize linear table
{
L = (SqList*)malloc(sizeof(SqList)); // Allocate space
L->length = 0; // Make the length 0
}
void CreatList(SqList*& L) // Build a linear table
{
int n, i, e;
cin >> n;
for (i = 0; i < n; i++)
{
cin >> e;
L->data[i] = e;
L->length++;
}
}
int ListLength(SqList* L)
{
return (L->length);
}
int LocateElem(SqList* L, ElemType e)
{
int i = 0;
while (i < L->length && L->data[i] != e)
i++;
if (i >= L->length)
return 0;
else
return i + 1; // Find the logical sequence number that returns him
}
bool GetElem(SqList* L, int i, ElemType& e)
{
if (i<1 || i>L->length) return false;
e = L->data[i - 1];
return true;
}
bool ListInsert(SqList*& L, int i, ElemType e)
{
int j;
if (i<1 || i>L->length+1 || L->length == MaxSize)
return false;
i--;
for (j = L->length; j > i; j--)
{
L->data[j] = L->data[j - 1];
}
L->data[i] = e;
L->length++;
return true;
}
void UnionList(SqList * & LA, SqList *& LB, SqList *& LC)
{
int i, lena;
InitList(LC);
ElemType e;
for (i = 1; i <= ListLength(LA); i++)
{
GetElem(LA, i, e);
ListInsert(LC, i, e);
}
lena = ListLength(LA);
for (i = 1; i <= ListLength(LB); i++)
{
GetElem(LB, i, e);
if (!LocateElem(LA, e))
{
ListInsert(LC, ++lena, e);
}
}
}
void DispList(SqList* L)
{
for (int i = 0; i < L->length; i++)
{
cout << L->data[i] << " ";
}
cout << endl;
}
int main()
{
SqList* L1, *L2, *L3;
InitList(L1);
CreatList(L1);
InitList(L2);
CreatList(L2);
UnionList(L1, L2, L3);
DispList(L3);
return 0;
}
边栏推荐
- CDA Level1知识点总结之业务数据分析
- UI prototype resources
- pytorch使用tensorboard实现可视化总结
- First knowledge of opencv4.x ---- mean filtering
- ISP图像信号处理
- 【数据挖掘】第三章 数据分析基础
- ARMV8体系结构简介
- How to import a large amount of data in MATLAB
- Creation of adjacency matrix of undirected connected graph output breadth depth traversal
- CUDA explanation - why GPU is used in deep learning
猜你喜欢

手持振弦采集仪对振弦传感器激励方法和激励电压

AI模型风险评估 第1部分:动机

基于PackNet的演进——丰田研究院(TRI)深度估计文章盘点(上)
![[dimension reduction strike] Hilbert curve](/img/bb/c2488f29721bdc413d709ee4bfaddf.png)
[dimension reduction strike] Hilbert curve
![[deep learning] convolutional neural network](/img/36/081f9e38886f5a7ed4d641761db4b7.png)
[deep learning] convolutional neural network

深度估计自监督模型monodepth2论文总结和源码分析【理论部分】

初识Opencv4.X----为图像添加高斯噪声

Get to know opencv4.x for the first time --- add Gaussian noise to the image
![[deep learning] self encoder](/img/7e/c3229b489ec72ba5d527f6a00ace01.png)
[deep learning] self encoder

CDA Level1知识点总结之业务分析报告与数据可视化报表
随机推荐
【深度学习】自编码器
ADC介绍
Temperature, humidity and light intensity acquisition based on smart cloud platform
【机器翻译】SCONES——用多标签任务做机器翻译
ARM预备知识
Segmentation-based deep-learning approach for surface-defectdetection(基于分割的表面缺陷深度学习检测方法)
深度估计自监督模型monodepth2在自己数据集的实战——单卡/多卡训练、推理、Onnx转换和量化指标评估
Flutter rive multi state example
多通道振弦、温度、模拟传感信号采集仪数据查看和参数修改
数据分析业务核心
First knowledge of opencv4.x --- image histogram matching
Save pdf2image PDF file as JPG nodejs implementation
A number converted from a decimal integer to another base
Binary Cross Entropy真的适合多标签分类吗?
CDA LEVELⅠ2021新版模拟题一(附答案)
Wechat applet realizes the rotation map (automatic switching & manual switching)
Evolution based on packnet -- review of depth estimation articles of Toyota Research Institute (TRI) (Part 2)
【深度学习】卷积神经网络
初识Opencv4.X----图像直方图绘制
How to install pytorch—— A most simple and effective method!