-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path线性表应用_集合操作_.cpp
122 lines (97 loc) · 1.65 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include<stdio.h>
#include<stdlib.h>
#define typeElem int
typedef struct Node
{
struct Node *next;
typeElem data;
}SetNode;
typedef struct{
SetNode *first;
}LinkSet;// Á´Ê½¼¯ºÏÃû³ÆÖ¸Õë
void InitList(LinkSet &s)
{
s.first=NULL;
}
int numSet(LinkSet s,typeElem e)
{
while(s.first!=NULL)
{
if(s.first->data==e)
{
//printf("%d \n",s1.first->data);
return 0;
}
s.first=s.first->next;
}
return 1;
}
void InsertElem(LinkSet &s,typeElem e)
{
if(numSet(s,e))
{
SetNode *p,*tail;
LinkSet t;
p=(SetNode*)malloc(sizeof(SetNode));
p->data=e;
//printf("%d ",e);
p->next=NULL;
if(s.first==NULL)
{
s.first=p;
}
else
{
tail->next=p;
//t.first=p;
}
tail=p;
}
}
void PrintSet(LinkSet s)
{
while(s.first!=NULL)
{
printf("%d \n",s.first->data);
s.first=s.first->next;
}
}
void MergeSet(LinkSet la,LinkSet lb,LinkSet &lc)
{
while(la.first!=NULL)
{
//printf("%d \n",la.first->data);
InsertElem(lc,la.first->data);
la.first=la.first->next;
}
while(lb.first!=NULL)
{
//printf("%d \n",lb.first->data);
InsertElem(lc,lb.first->data);
lb.first=lb.first->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,5);
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("%d ",1);
}