forked from Vencenter/C_Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path线性表应用_集合操作__.cpp
97 lines (76 loc) · 1.4 KB
/
线性表应用_集合操作__.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include<stdio.h>
#include<stdlib.h>
#define typeElem int
typedef struct Node
{
struct Node *next;
typeElem data;
}SetNode,*LinkSet;
void InitList(LinkSet &s)
{
s=(SetNode*)malloc(sizeof(SetNode));
s->next=NULL;
}
void InsertElem(LinkSet &s,typeElem e)
{
SetNode *p,*t=s,*tail;
p=(SetNode*)malloc(sizeof(SetNode));
p->data=e;
p->next=NULL;
while(t->next!=NULL)
{
if(t->next->data==e)
{
return;
}
t=t->next;
}
t->next=p;
}
void PrintSet(LinkSet s)
{
while(s->next!=NULL)
{
printf("%d \n",s->next->data);
s->next=s->next->next;
}
}
void MergeSet(LinkSet la,LinkSet lb,LinkSet &lc)
{
while(la->next!=NULL)
{
//printf("%d \n",la->data->data);
InsertElem(lc,la->next->data);
la->next=la->next->next;
}
while(lb->next!=NULL)
{
//printf("%d \n",lb->data->data);
InsertElem(lc,lb->next->data);
lb->next=lb->next->next;
}
}
int main()
{
LinkSet la,lb,lc;
InitList(la);
InitList(lb);
InitList(lc);
InsertElem(la,3);
InsertElem(la,2);
InsertElem(la,4);
InsertElem(la,7);
InsertElem(la,2);
InsertElem(lb,3);
InsertElem(lb,2);
InsertElem(lb,1);
InsertElem(lb,6);
InsertElem(lb,8);
//PrintSet(la);
printf("\n");
//PrintSet(lb);
MergeSet(la,lb,lc);
printf("****************\n");
PrintSet(lc);
printf("****************\n");
}