This commit is contained in:
2024-03-07 22:59:04 +08:00
parent 79c0a970f0
commit 68d6c32692
5 changed files with 411 additions and 0 deletions

40
homework240306/main.cpp Normal file
View File

@@ -0,0 +1,40 @@
#include <iostream>
using namespace std;
#include "SqList.h"
template <class DT>
void Intersection(SqList<DT>& A, const SqList<DT>& B)
{
int k = 0;
for (int i = 0; i < A.length; ++i)
{
if (LocateElem_e(B, A.elem[i]) > 0)
{
A.elem[k++] = A.elem[i];
}
}
A.length = k;
}
int main()
{
SqList<int> A;
SqList<int> B;
InitList(A, 32);
InitList(B, 32);
int length_a, length_b;
cout << "请输入集合A的元素个数: ";
cin >> length_a;
CreateList(A, length_a);
cout << "请输入集合B的元素个数: ";
cin >> length_b;
CreateList(B, length_b);
cout << "集合A: ";
DispList(A);
cout << "集合B: ";
DispList(B);
Intersection(A, B);
cout << "A∩B: ";
DispList(A);
DestroyList(A);
DestroyList(B);
return 0;
}