A.B.C 为递增有序线性表,删去A中即在B出现也在C出现的元素。
为啥啥也输出不出来啊
#include <bits/stdc++.h>
using namespace std;
typedef int LLDataType;
typedef struct LinkList {
LLDataType data;
struct LinkList* next;
}Link;
void CreateLinkList (Link* &head, int n)
{
head = (Link*)malloc(sizeof(Link));
head->next = NULL;
Link* tail = head;
while (n--)
{
Link* a = (Link*)malloc(sizeof(Link));
a->next = NULL;
scanf("%d", &a->data);
tail->next = a;
tail = a;
}
return;
}
void IntersectionDelete (Link* &L, Link* L2, Link* L3)
{
Link* L1 = L;
while (L2 && L3)
{
if (L2->data == L3->data)
{
while (L1)
{
if (L1->next->data == L2->data)
{
Link* del = L1->next;
L1->next = L1->next->next;
free (del);
}
else L1 = L1->next;
}
L2 = L2->next;
L3 = L3->next;
}
else if (L2->data < L3->data)
L2 = L2->next;
else
L3 = L3->next;
}
return;
}
void LinkListPrint (Link* L)
{
Link* L1 = L->next;
while (L1)
{
printf ("%d ", L1->data);
L1 = L1->next;
}
puts ("");
}
int main ()
{
Link *La, *Lb, *Lc;
int na, nb, nc;
cout << "请输入表A的长度\n";
cin >> na;
cout << "请输入表A\n";
CreateLinkList (La, na);
cout << "请输入表B的长度\n";
cin >> nb;
cout << "请输入表B\n";
CreateLinkList (Lb, nb);
cout << "请输入表C的长度\n";
cin >> nc;
cout << "请输入表C\n";
CreateLinkList (Lc, nc);
IntersectionDelete (La, Lb, Lc);
cout << "删除Lb和Lc交集元素的La为\n";
LinkListPrint (La);
return 0;
}