#include <iostream>
using namespace std;
#define max 100
#define ok 1
#define error 0
typedef struct
{
int *elem;
int length;
} list;
void chuangianshunxubiao(list &l)
{
l.elem = new int[max];
l.length = 0;
}
int changdu(list l)
{
return l.length;
}
void quyuansu(list l, int i, int &e)
{
e = l.elem[i - 1];
}
bool panduan(list l, int e)
{
int i;
for (i = 0; i < l.length; i++)
{
if (e == l.elem[i])
{
return true;
}
}
return false;
}
void zuihou(list &l, int e)
{
l.elem[l.length] = e;
l.length++;
}
void print(list l)
{
int i;
for (int i = 0; i < l.length; i++)
{
cout << l.elem[i] << " ";
}
cout << endl;
}
void hebing(list &la, list lb)
{
int temp, i;
int lenga = changdu(la);
int lengb = changdu(lb);
for (i = 1; i <= lengb; i++)
{
quyuansu(lb, i, temp);
if (!panduan(la, temp))
{
zuihou(la, temp);
}
}
}
void shuru(list &l, int n)
{
int i;
for (int i = 0; i < n; i++)
{
cout << "请输入" << i + 1 << "个数" << endl;
cin >> l.elem[i];
}
l.length = n;
}
int main ()
{
list la, lb;
int n, m;
chuangianshunxubiao(la);
chuangianshunxubiao(lb);
cout << "请输入线性表la的个数" << endl;
cin >> n;
shuru(la, n);
cout << "请输入线性表lb的个数" << endl;
cin >> m;
shuru(lb, m);
print(la);
print(lb);
hebing(la, lb);
print(la);
return 0;
}
![在这里插入图片描述](https:
|